Open
Description
context
dash 2.18.2
dash-core-components 1.7.1
dash-html-components 2.0.0
dash-renderer 2.0.0
dash-table 5.0.0
Description
The problem I have can be reproduced running the following app:
from time import sleep
import dash
from dash import callback, dcc, html, Output, Input, State
app = dash.Dash(__name__, serve_locally=False)
app.layout = html.Div(
[
html.Div("orig",id="display"),
dcc.Input(id='input', value='Initial Value', type='text'),
html.Button('Submit', id='submit-btn', n_clicks=0),
dcc.Store(id="store-1"),
dcc.Store(id="store-2"),
]
)
app.enable_dev_tools(debug=True)
server = app.server
@callback(
Output("display", "children"),
Input("store-1", "data"),
Input("store-2", "data"),
prevent_initial_call=True,
)
def display(store1, store2):
print(f"display triggered, input ({store1}, {store2})")
return f"store1: {store1}, store2: {store2}"
@callback(
Output("store-1", "data"),
Input("submit-btn", "n_clicks"),
State("input", "value"),
prevent_initial_call=True,
)
def submit(_, text):
return text
@callback(
Output("store-1", "data",allow_duplicate=True),
Output("store-2", "data"),
Input("store-1", "data"),
prevent_initial_call=True,
)
def process(text):
print("process triggered")
sleep(3)
print("process ended")
return (f"processed1-{text}", f"processed2-{text}")
Actual behavior
When I click on the button, I get:
submit
callback is triggered -> store-1
modified -> onlyprocess
callback is triggered -> eventually process
finishes -> store-1
and store-2
modified -> display
is triggered
and in the logs I see:
process triggered
process ended
display triggered, input (processed1-Initial Value, processed2-Initial Value)
The first store-1
change should have triggered the display
callback directly.
Expected behavior
When I click on the button:
submit
callback is triggered -> store-1
modified -> both process
and display
callback should be triggered at the same time -> eventually process
finishes -> store-1
and store-2
modified -> display
is triggered
i.e. I should have seen in the logs:
process triggered
display triggered, input (Initial Value, None)
process ended
display triggered, input (processed1-Initial Value, processed2-Initial Value)