Skip to content

Commit c2d4637

Browse files
simeonschwarzenbergSimeon Schwarzenbergcpsievert
authored
Closes #206: preserve plotly FigureWidget layout callbacks (#207)
Co-authored-by: Simeon Schwarzenberg <simeon.schwarzenberg@enas.fraunhofer.de> Co-authored-by: Carson <cpsievert1@gmail.com>
1 parent 9d36df5 commit c2d4637

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [UNRELEASED]
99

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

1213
## [0.6.2] - 2025-05-21
1314

shinywidgets/_render_widget_base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def set_layout_defaults(widget: Widget) -> Tuple[Widget, bool]:
173173

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

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

193-
widget.layout = layout
194+
if isinstance(widget, BaseFigureWidget):
195+
# Reassigning the layout to a FigureWidget drops installed callbacks;
196+
# use native update_layout instead.
197+
widget.update_layout(layout)
198+
else:
199+
widget.layout = layout
194200

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

0 commit comments

Comments
 (0)