@@ -177,47 +177,63 @@ def update_out(n_clicks):
177177 assert dash_duo .get_logs () == []
178178
179179
180- @pytest .mark .skip (reason = "https://github.com/plotly/dash/issues/1105" )
181180def test_cbsc004_callback_using_unloaded_async_component (dash_duo ):
182181 app = dash .Dash ()
183- app .layout = html .Div (
184- children = [
185- dcc .Tabs (
186- children = [
187- dcc .Tab (
188- children = [
189- html .Button (id = "btn" , children = "Update Input" ),
190- html .Div (id = "output" , children = ["Hello" ]),
191- ]
192- ),
193- dcc .Tab (
194- children = dash_table .DataTable (
195- id = "other-table" ,
196- columns = [{"id" : "a" , "name" : "A" }],
197- data = [{"a" : "b" }]
198- )
199- ),
200- ]
201- )
202- ]
203- )
182+ app .layout = html .Div ([
183+ dcc .Tabs ([
184+ dcc .Tab ("boo!" ),
185+ dcc .Tab (
186+ dash_table .DataTable (
187+ id = "table" ,
188+ columns = [{"id" : "a" , "name" : "A" }],
189+ data = [{"a" : "b" }]
190+ )
191+ ),
192+ ]),
193+ html .Button ("Update Input" , id = "btn" ),
194+ html .Div ("Hello" , id = "output" ),
195+ html .Div (id = "output2" )
196+ ])
204197
205198 @app .callback (
206199 Output ("output" , "children" ),
207200 [Input ("btn" , "n_clicks" )],
208- [State ("other- table" , "data" )]
201+ [State ("table" , "data" )]
209202 )
210203 def update_out (n_clicks , data ):
211- if n_clicks is None :
212- return len (data )
204+ return json .dumps (data ) + ' - ' + str (n_clicks )
213205
206+ @app .callback (
207+ Output ("output2" , "children" ),
208+ [Input ("btn" , "n_clicks" )],
209+ [State ("table" , "derived_viewport_data" )]
210+ )
211+ def update_out2 (n_clicks , data ):
214212 return json .dumps (data ) + ' - ' + str (n_clicks )
215213
216214 dash_duo .start_server (app )
217215
218216 dash_duo .wait_for_text_to_equal ("#output" , '[{"a": "b"}] - None' )
217+ dash_duo .wait_for_text_to_equal ("#output2" , 'null - None' )
218+
219219 dash_duo .find_element ("#btn" ).click ()
220220 dash_duo .wait_for_text_to_equal ("#output" , '[{"a": "b"}] - 1' )
221+ dash_duo .wait_for_text_to_equal ("#output2" , 'null - 1' )
222+
223+ dash_duo .find_element (".tab:not(.tab--selected)" ).click ()
224+ dash_duo .wait_for_text_to_equal ("#table th" , "A" )
225+ # table props are in state so no change yet
226+ dash_duo .wait_for_text_to_equal ("#output2" , 'null - 1' )
227+
228+ # repeat a few times, since one of the failure modes I saw during dev was
229+ # intermittent - but predictably so?
230+ for i in range (2 , 10 ):
231+ expected = '[{"a": "b"}] - ' + str (i )
232+ dash_duo .find_element ("#btn" ).click ()
233+ dash_duo .wait_for_text_to_equal ("#output" , expected )
234+ # now derived props are available
235+ dash_duo .wait_for_text_to_equal ("#output2" , expected )
236+
221237 assert dash_duo .get_logs () == []
222238
223239
0 commit comments