26
26
from shiny .http_staticfiles import StaticFiles
27
27
from shiny .render import RenderFunction , RenderFunctionAsync
28
28
from shiny .session import get_current_session , require_active_session
29
+ from shiny .module import resolve_id
29
30
30
31
from ._comm import BufferType , ShinyComm , ShinyCommManager
31
32
from ._dependencies import (
39
40
def output_widget (
40
41
id : str , * , width : Optional [str ] = None , height : Optional [str ] = None
41
42
) -> Tag :
43
+ id = resolve_id (id )
42
44
return tags .div (
43
45
* libembed_dependency (),
44
46
output_binding_dependency (),
@@ -59,6 +61,10 @@ def init_shiny_widget(w: Widget):
59
61
raise RuntimeError (
60
62
"shinywidgets requires that all ipywidgets be constructed within an active Shiny session"
61
63
)
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
62
68
63
69
# `Widget` has `comm = Instance('ipykernel.comm.Comm')` which means we'd get a
64
70
# runtime error if we try to set this attribute to a different class, but
@@ -121,9 +127,9 @@ def init_shiny_widget(w: Widget):
121
127
# Handle messages from the client. Note that widgets like qgrid send client->server messages
122
128
# to figure out things like what filter to be shown in the table.
123
129
@reactive .Effect
124
- @reactive .event (session .input [ " shinywidgets_comm_send" ] )
130
+ @reactive .event (session .input . shinywidgets_comm_send )
125
131
def _ ():
126
- msg_txt = session .input [ " shinywidgets_comm_send" ] ()
132
+ msg_txt = session .input . shinywidgets_comm_send ()
127
133
msg = json .loads (msg_txt )
128
134
comm_id = msg ["content" ]["comm_id" ]
129
135
comm : ShinyComm = COMM_MANAGER .comms [comm_id ]
0 commit comments