Open devmcp opened 4 years ago
I also faced the same issue with my dcc.store()
.
I update the store in a client-side call and then call the server callback.
here's a version inspired by your example.
dash 2.4.1 pypi_0 pypi
dash-core-components 2.0.0 pypi_0 pypi
dash-html-components 2.0.0 pypi_0 pypi
dash-daq 0.5.0 pypi_0 pypi
import datetime
import dash
from dash import html, dcc
from dash.dependencies import Output, Input, State
from dash.exceptions import PreventUpdate
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.Store(id="local", storage_type="local"),
html.Div(html.Button("localStorage", id="local-button")),
html.Div(0, id="local-clicks"),
]
)
app.clientside_callback(
"""
function(n_clicks, data) {
if (n_clicks) {
console.log("Updating data store");
data = data || {clicks: 0};
data.clicks = data.clicks + 1;
return data;
}
}
""",
Output("local", "data"),
[Input("local-button", "n_clicks")],
[State("local", "data")],
)
@app.callback(
Output("local-clicks", "children"),
[Input("local", "modified_timestamp")],
[State("local", "data")],
)
def on_data(ts, data):
print(datetime.datetime.now())
print(f"New data found! ({ts}, {data})")
print("-" * 20)
return f"{ts} - {data['clicks']}"
if __name__ == "__main__":
app.run_server(debug=True, port=8077)
2022-06-25 15:22:20.186572
New data found! (1656150740170, {'clicks': 85})
--------------------
and in the browser console
Please help, is someplace I can look at if to resolve this.
Describe your context
Describe the bug
The dcc.Storage component seems to trigger twice (sometimes more) on starting the app and sometimes on subsequent triggers. See example below.
Minimal working example code:
Example output:
Expected behavior
The callback should fire once.