Repository navigation
Fix: bokeh figures with only a width or height no longer over-correct - #509
Merged
Merged
Conversation
A figure given only a height now fills the available width and keeps that height (sizing_mode="stretch_width"); one given only a width keeps that width and fills the available height (sizing_mode="stretch_height"). Previously any explicit sizing property at all (even just a height) made shinywidgets leave bokeh's own sizing untouched, so a bare height=200 rendered at bokeh's default 600px width, overflowing its card. Co-authored-by: Claude <noreply@anthropic.com>
✅ Deploy Preview for shinywidgets canceled.
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The sizing assertions allow plots to overflow their containers, so both width and height checks need a two-sided 2px tolerance to reject overflow as well as undersizing.
1 open issue
What changed in this PR
This PR refines Bokeh figure sizing in shinywidgets: figures with only one explicit dimension keep it while stretching along the other axis.
Changes:
- Selects
stretch_widthfor height-only figures andstretch_heightfor width-only figures, preserving explicit sizing overrides. - Adds unit and browser tests for partial sizing and output fill behavior.
- Updates the renderer documentation, website guide, bundled skill reference, and changelog.
| File | Description |
|---|---|
website/widgets/bokeh/index.md |
Explains partial-dimension sizing behavior. |
tests/unit/test_render_widget_base_layout_defaults.py |
Tests output fill decisions for partial sizes. |
tests/unit/test_as_widget.py |
Tests sizing-mode selection and explicit overrides. |
tests/playwright/bokeh_sizing/test_bokeh_sizing.py |
Adds browser checks for height-only and width-only figures. |
tests/playwright/bokeh_sizing/app.py |
Adds partial-size browser test fixtures. |
shinywidgets/.agents/skills/shinywidgets/references/widgets/bokeh.md |
Aligns bundled guidance with the new behavior. |
shinywidgets/_render_widget.py |
Updates the render_bokeh sizing docstring. |
shinywidgets/_as_widget.py |
Chooses stretch modes based on explicit dimensions. |
CHANGELOG.md |
Clarifies the Bokeh sizing fix. |
Review effort: Balanced
cpsievert
marked this pull request as ready for review
November 30, 2026 18:34
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why
Unreleased work on
mainstopped bokeh figures from always stretching to fill their output, so awidthorheightyou set is no longer ignored. But it went too far:figure(height=200)now renders at bokeh's default 600px width and overflows its card.What changes
A
figurefills its output in any direction you don't give it a size:figure()figure(height=200)figure(width=250)figure(width=250, height=150)An explicit
sizing_modeoraspect_ratioturns this off, as it already did.I checked in Chromium: in a 400px-tall card,
figure(height=200)now fills the card's width (432px) at 200px tall, wheremaingave 600×200.Test plan
as_widget_bokeh()and the output's fill choicebokeh_sizing/. The test for a figure with no size now also fails if the plot is bigger than its output, not only smaller.check_docs.py, agent skill tests,make check-format,make check-types