|
| 1 | +from dash import html, Dash, Input, Output |
| 2 | + |
| 3 | + |
| 4 | +def test_dync001_dynamic_callback(dash_duo): |
| 5 | + app = Dash() |
| 6 | + |
| 7 | + app.layout = html.Div( |
| 8 | + [ |
| 9 | + html.Div(id="output"), |
| 10 | + html.Button("create", id="create"), |
| 11 | + html.Div("initial", id="output-2"), |
| 12 | + html.Button("dynamic", id="dynamic"), |
| 13 | + ] |
| 14 | + ) |
| 15 | + |
| 16 | + @app.callback( |
| 17 | + Output("output", "children"), |
| 18 | + Input("create", "n_clicks"), |
| 19 | + _allow_dynamic_callbacks=True, |
| 20 | + prevent_initial_call=True, |
| 21 | + ) |
| 22 | + def on_click(n_clicks): |
| 23 | + @app.callback( |
| 24 | + Output("output-2", "children"), |
| 25 | + Input("dynamic", "n_clicks"), |
| 26 | + prevent_initial_call=True, |
| 27 | + ) |
| 28 | + def on_click2(n_clicks2): |
| 29 | + return f"Dynamic clicks {n_clicks2}" |
| 30 | + |
| 31 | + return f"creator {n_clicks}" |
| 32 | + |
| 33 | + dash_duo.start_server(app) |
| 34 | + |
| 35 | + dash_duo.wait_for_element("#create").click() |
| 36 | + dash_duo.wait_for_text_to_equal("#output", "creator 1") |
| 37 | + |
| 38 | + dash_duo.wait_for_element("#dynamic").click() |
| 39 | + dash_duo.wait_for_text_to_equal("#output-2", "Dynamic clicks 1") |
0 commit comments