Skip to content

Commit 39467d6

Browse files
committed
Fix events from within modules too
1 parent d5f58b1 commit 39467d6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

shinywidgets/_shinywidgets.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def init_shiny_widget(w: Widget):
6161
raise RuntimeError(
6262
"shinywidgets requires that all ipywidgets be constructed within an active Shiny session"
6363
)
64+
# Break out of any module-specific session. Otherwise, input.shinywidgets_comm_send
65+
# will be some module-specific copy.
66+
while hasattr(session, "_parent"):
67+
session = session._parent
6468

6569
# `Widget` has `comm = Instance('ipykernel.comm.Comm')` which means we'd get a
6670
# runtime error if we try to set this attribute to a different class, but
@@ -123,9 +127,9 @@ def init_shiny_widget(w: Widget):
123127
# Handle messages from the client. Note that widgets like qgrid send client->server messages
124128
# to figure out things like what filter to be shown in the table.
125129
@reactive.Effect
126-
@reactive.event(session.input["shinywidgets_comm_send"])
130+
@reactive.event(session.input.shinywidgets_comm_send)
127131
def _():
128-
msg_txt = session.input["shinywidgets_comm_send"]()
132+
msg_txt = session.input.shinywidgets_comm_send()
129133
msg = json.loads(msg_txt)
130134
comm_id = msg["content"]["comm_id"]
131135
comm: ShinyComm = COMM_MANAGER.comms[comm_id]

0 commit comments

Comments
 (0)