Skip to content

Fix: bokeh figures with only a width or height no longer over-correct - #509

Merged
cpsievert merged 3 commits into
mainfrom
fix/bokeh-partial-sizing
Nov 30, 2026
Merged

cpsievert merged 3 commits into
mainfrom
fix/bokeh-partial-sizing

Conversation

@cpsievert

@cpsievert cpsievert commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Unreleased work on main stopped bokeh figures from always stretching to fill their output, so a width or height you 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 figure fills its output in any direction you don't give it a size:

you write you get
figure() fills both ways (unchanged)
figure(height=200) fills the width, 200px tall
figure(width=250) 250px wide, fills the height
figure(width=250, height=150) 250×150 (unchanged)

An explicit sizing_mode or aspect_ratio turns 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, where main gave 600×200.

Test plan

  • Unit tests for the height-only and width-only cases, in both as_widget_bokeh() and the output's fill choice
  • Two new Playwright cases in bokeh_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

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>
@netlify

netlify Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for shinywidgets canceled.

Name Link
🔨 Latest commit ae8bcc0
🔍 Latest deploy log https://app.netlify.com/projects/shinywidgets/deploys/6b0dc334acd71e6ea61f9506

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request November 23, 2026 23:17 Inactive
@cpsievert
cpsievert requested a balanced review from Copilot November 23, 2026 23:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_width for height-only figures and stretch_height for 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
cpsievert requested a balanced review from Copilot November 23, 2026 23:31
@github-actions
github-actions Bot temporarily deployed to pull request November 23, 2026 23:32 Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the Bokeh partial-sizing change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@cpsievert
cpsievert marked this pull request as ready for review November 30, 2026 18:34
@github-actions
github-actions Bot temporarily deployed to pull request November 30, 2026 18:44 Inactive
@cpsievert
cpsievert merged commit 33108bc into main Nov 30, 2026
18 checks passed

This branch was previously deployed

1 inactive deployment
pull request — ae8bcc02 Deployed Nov 30, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants