I noticed that option prevent_initial_callbacks
stopped working.
I try to investigate, did updare dash, put commands to prevent callbacks from firing as general and for individual callbacks. Each time after starting an app all callbacks are executed.
My versions:
$ conda list dash
Name Version Build Channel
dash 1.16.3 py_0
dash-core-components 1.3.1 py_0
dash-html-components 1.0.1 py_0
dash-renderer 1.1.2 py_0
dash-table 4.4.1 py_0
jupyter-dash 0.3.0 py_0 plotly
Below is sample code from Dash documentation (modified for JupLab) where all callbacks are triggered at initialization.
Do you have idea how to prevent callbacks from firing at start?
Or, can you confirm/deny similar behaviour on your machines.
import dash
from dash.dependencies import Input, Output
import dash_html_components as html
from datetime import datetime
import time
from jupyter_dash import JupyterDash
app = JupyterDash(prevent_initial_callbacks=True)
# app = dash.Dash()
app.layout = html.Div(
[
html.Button("execute callbacks", id="button_2"),
html.Div(children="callback not executed", id="first_output_2"),
html.Div(children="callback not executed", id="second_output_2"),
html.Div(children="callback not executed", id="third_output_2"),
html.Div(children="callback not executed", id="fourth_output_2"),
]
)
@app.callback(
[Output("first_output_2", "children"), Output("second_output_2", "children")],
[Input("button_2", "n_clicks")], prevent_initial_call=True)
def first_callback(n):
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
return ["in the first callback it is " + current_time, "in the first callback it is " + current_time]
@app.callback(
Output("third_output_2", "children"), [Input("second_output_2", "children")], prevent_initial_call=True)
def second_callback(n):
time.sleep(2)
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
return "in the second callback it is " + current_time
@app.callback(
Output("fourth_output_2", "children"),
[Input("first_output_2", "children"), Input("third_output_2", "children")], prevent_initial_call=True)
def third_output(n, m):
time.sleep(2)
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
return "in the third callback it is " + current_time
# if __name__ == '__main__':
# app.run_server(debug=True)
app.run_server(mode='external', port = 8050, dev_tools_ui=True,
dev_tools_hot_reload =True, threaded=True)