@@ -137,12 +137,6 @@ class Renderer(Generic[IT]):
137
137
asynchonously.
138
138
"""
139
139
140
- # Set _session here because some subclasses of Renderer (e.g. data_frame) set
141
- # self._session before calling super().__init__(). If we were to set
142
- # self._session=None in the __init__ method here, it would overwrite the value from
143
- # the subclass. We avoid that by setting it here.
144
- _session : Session | None = None
145
-
146
140
def __call__ (self , _fn : ValueFn [IT ]) -> Self :
147
141
"""
148
142
Add the value function to the renderer.
@@ -163,6 +157,7 @@ def __call__(self, _fn: ValueFn[IT]) -> Self:
163
157
:
164
158
Original renderer instance.
165
159
"""
160
+ from ...session import get_current_session
166
161
167
162
if not callable (_fn ):
168
163
raise TypeError ("Value function must be callable" )
@@ -179,6 +174,8 @@ def __call__(self, _fn: ValueFn[IT]) -> Self:
179
174
# for auto-registration to occur.
180
175
self .output_id = self .__name__
181
176
177
+ self ._session = get_current_session ()
178
+
182
179
# Allow for App authors to not require `@output`
183
180
self ._auto_register ()
184
181
@@ -220,6 +217,7 @@ def __init__(
220
217
# """
221
218
# Renderer - init docs here
222
219
# """
220
+ self ._session : Session | None = None
223
221
super ().__init__ ()
224
222
225
223
self ._auto_registered : bool = False
@@ -331,16 +329,12 @@ def _auto_register(self) -> None:
331
329
"""
332
330
# If in Express mode, register the output
333
331
if not self ._auto_registered :
334
- from ...session import get_current_session
335
-
336
- s = get_current_session ()
337
- if s is not None :
332
+ if self ._session is not None :
338
333
# Register output on reactive graph
339
- s .output (self )
334
+ self . _session .output (self )
340
335
# We mark the fact that we're auto-registered so that, if an explicit
341
336
# registration now occurs, we can undo this auto-registration.
342
337
self ._auto_registered = True
343
- self ._session = s
344
338
345
339
346
340
# Not inheriting from `WrapAsync[[], IT]` as python 3.8 needs typing extensions that
0 commit comments