Skip to content

Commit 1d4d54c

Browse files
committed
Avoid the opening of an unknown/unnecessary comm
1 parent fafedbf commit 1d4d54c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

shinywidgets/_shinywidgets.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,19 @@ def _cleanup_session_state():
111111

112112
id = cast(str, w._model_id)
113113

114+
# Since the actual ShinyComm() is initialized _after_ the Widget is initialized,
115+
# and Widget.__init__() includes a call to Widget.open() which opens an unnecessary
116+
# comm, we just set the comm to a dummy comm for now (to avoid unnecessary work)
117+
w.comm = OrphanedShinyComm(id)
118+
114119
# Schedule the opening of the comm to happen sometime after this init function.
115120
# This is important for widgets like plotly that do additional initialization that
116121
# is required to get a valid widget state.
117122
@reactive.effect(priority=99999)
118-
def _open_comm():
123+
def _open_shiny_comm():
119124

120-
# Call _repr_mimebundle_() before getting the state since it may modify the widget
121-
# in an important way (unfortunately, plotly does this)
125+
# Call _repr_mimebundle_() before get_state() since it may modify the widget
126+
# in an important way (unfortunately, it does for plotly)
122127
# # https://github.com/plotly/plotly.py/blob/0089f32/packages/python/plotly/plotly/basewidget.py#L734-L738
123128
w._repr_mimebundle_()
124129

@@ -138,7 +143,7 @@ def _open_comm():
138143
html_deps=session._process_ui(TagList(widget_dep))["deps"],
139144
)
140145

141-
_open_comm.destroy()
146+
_open_shiny_comm.destroy()
142147

143148
# If we're in a reactive context, close this widget when the context is invalidated
144149
# TODO: this should probably only be done in an output context, but I'm pretty sure

0 commit comments

Comments
 (0)