-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathapp_error.py
45 lines (36 loc) · 1.16 KB
/
app_error.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import time
import dash
from dash import html
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
from tests.integration.long_callback.utils import get_long_callback_manager
long_callback_manager = get_long_callback_manager()
handle = long_callback_manager.handle
app = dash.Dash(__name__, long_callback_manager=long_callback_manager)
app.enable_dev_tools(debug=True, dev_tools_ui=True)
app.layout = html.Div(
[
html.Div([html.P(id="output", children=["Button not clicked"])]),
html.Button(id="button", children="Run Job!"),
]
)
@app.long_callback(
output=Output("output", "children"),
inputs=Input("button", "n_clicks"),
running=[
(Output("button", "disabled"), True, False),
],
prevent_initial_call=True,
)
def callback(n_clicks):
if os.getenv("LONG_CALLBACK_MANAGER") != "celery":
# Diskmanager needs some time, celery takes too long.
time.sleep(1)
if n_clicks == 2:
raise Exception("bad error")
if n_clicks == 4:
raise PreventUpdate
return f"Clicked {n_clicks} times"
if __name__ == "__main__":
app.run_server(debug=True)