|
| 1 | +from dash import Dash, Input, Output, State, html, clientside_callback |
| 2 | +import time |
| 3 | + |
| 4 | +from tests.integration.long_callback.utils import get_long_callback_manager |
| 5 | + |
| 6 | +long_callback_manager = get_long_callback_manager() |
| 7 | +handle = long_callback_manager.handle |
| 8 | + |
| 9 | +app = Dash(__name__, long_callback_manager=long_callback_manager) |
| 10 | + |
| 11 | +app.layout = html.Div( |
| 12 | + [ |
| 13 | + html.Button("Start", id="start"), |
| 14 | + html.Div(id="output"), |
| 15 | + html.Div(id="progress-output"), |
| 16 | + html.Div(0, id="progress-counter"), |
| 17 | + ] |
| 18 | +) |
| 19 | + |
| 20 | +clientside_callback( |
| 21 | + "function(_, previous) { return parseInt(previous) + 1;}", |
| 22 | + Output("progress-counter", "children"), |
| 23 | + Input("progress-output", "children"), |
| 24 | + State("progress-counter", "children"), |
| 25 | + prevent_initial_call=True, |
| 26 | +) |
| 27 | + |
| 28 | + |
| 29 | +@app.callback( |
| 30 | + Output("output", "children"), |
| 31 | + Input("start", "n_clicks"), |
| 32 | + progress=Output("progress-output", "children"), |
| 33 | + interval=200, |
| 34 | + background=True, |
| 35 | + prevent_initial_call=True, |
| 36 | +) |
| 37 | +def on_bg_progress(set_progress, _): |
| 38 | + set_progress("start") |
| 39 | + time.sleep(2) |
| 40 | + set_progress("stop") |
| 41 | + return "done" |
| 42 | + |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + app.run_server(debug=True) |
0 commit comments