Skip to content

Commit 5cea47a

Browse files
author
Simeon Schwarzenberg
committed
Allow layout callbacks to be installed on a plotly FigureWidget
1 parent 9d36df5 commit 5cea47a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

shinywidgets/_render_widget_base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def set_layout_defaults(widget: Widget) -> Tuple[Widget, bool]:
174174
# Plotly provides it's own layout API (which isn't a subclass of ipywidgets.Layout)
175175
if pkg == "plotly":
176176
from plotly.graph_objs import Layout as PlotlyLayout # pyright: ignore
177+
from plotly.basewidget import BaseFigureWidget # pyright: ignore
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) # pyright: ignore
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)