Skip to content

Closes #206: preserve plotly FigureWidget layout callbacks #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [UNRELEASED]

* `datetime.date()` values are properly JSON serialized. (#204)
* Fixed an issue were callbacks on a plotly `FigureWidget` object were getting dropped with recent versions of plotly. (#207, thanks @simeonschwarzenberg)

## [0.6.2] - 2025-05-21

Expand Down
10 changes: 8 additions & 2 deletions shinywidgets/_render_widget_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def set_layout_defaults(widget: Widget) -> Tuple[Widget, bool]:

# Plotly provides it's own layout API (which isn't a subclass of ipywidgets.Layout)
if pkg == "plotly":
from plotly.graph_objs import Layout as PlotlyLayout # pyright: ignore
from plotly.graph_objs import Layout as PlotlyLayout
from plotly.basewidget import BaseFigureWidget

if isinstance(layout, PlotlyLayout):
if layout.height is not None:
Expand All @@ -190,7 +191,12 @@ def set_layout_defaults(widget: Widget) -> Tuple[Widget, bool]:
if fill:
widget._config = {"responsive": True, **widget._config} # type: ignore

widget.layout = layout
if isinstance(widget, BaseFigureWidget):
# Reassigning the layout to a FigureWidget drops installed callbacks;
# use native update_layout instead.
widget.update_layout(layout)
else:
widget.layout = layout

# altair, confusingly, isn't setup to fill it's Layout() container by default. I
# can't imagine a situation where you'd actually want it to _not_ fill the parent
Expand Down