@@ -111,14 +111,19 @@ def _cleanup_session_state():
111
111
112
112
id = cast (str , w ._model_id )
113
113
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
+
114
119
# Schedule the opening of the comm to happen sometime after this init function.
115
120
# This is important for widgets like plotly that do additional initialization that
116
121
# is required to get a valid widget state.
117
122
@reactive .effect (priority = 99999 )
118
- def _open_comm ():
123
+ def _open_shiny_comm ():
119
124
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 )
122
127
# # https://github.com/plotly/plotly.py/blob/0089f32/packages/python/plotly/plotly/basewidget.py#L734-L738
123
128
w ._repr_mimebundle_ ()
124
129
@@ -138,7 +143,7 @@ def _open_comm():
138
143
html_deps = session ._process_ui (TagList (widget_dep ))["deps" ],
139
144
)
140
145
141
- _open_comm .destroy ()
146
+ _open_shiny_comm .destroy ()
142
147
143
148
# If we're in a reactive context, close this widget when the context is invalidated
144
149
# TODO: this should probably only be done in an output context, but I'm pretty sure
0 commit comments