Hi all,
I’ve been working on a plotly dashboard application and I’m having an issue.
Context: I wrote an app that runs in django and it is used to plot timeseries and perform some calculations on them. Initially, the app parses a URL (which contains an ID) and then it makes a request of a timeseries and store the results in a dcc.Store component.
@app.callback(
[
Output(ids.TIMESERIES_STORE, "data"), # Store data for future use
Output(ids.MODULE_STORE, "data"),
],
Input(ids.URL, "search"),
prevent_initial_call=False, # Use centralized ID for URL
)
def initial_data_fetch(search):
Then, I use a callback to read from the store and plot the original data. The original data is always 5 days (a small timeframe since the Server where it comes from is kind of slow).
@app.callback(
[
Output(ids.GRAPH, "figure"),
Output(ids.GRAPH_CONTAINER, "style"),
Output(ids.SUMMARY_CONTAINER, "children"),
Output(ids.SUMMARY_CONTAINER, "style"),
Output(ids.STATS_STORE, "data"),
Output(ids.FIGURE_ORIGINAL, "data"),
Output(ids.FIGURE_STATS, "data"),
Output(ids.FIGURE_EXTREMES, "data"),
Output(ids.FIGURE_RETURN_VALUES, "data"),
],
[
Input(ids.ORIGINAL_TIMESERIES_BUTTON, "n_clicks"),
Input(ids.STATS_DROPDOWN, "value"),
Input(ids.EXTREMES_RADIOITEM, "value"),
Input(ids.TIMESERIES_STORE, "data"),
Input(ids.POT_INPUT, "value"),
Input(ids.ANALYSE_EXTREMES_BUTTON, "n_clicks"),
],
[State(ids.STATS_STORE, "data")],
prevent_initial_call=True,
)
def update_graph(
ts_clicks,
selected_year,
radioitem_value,
timeseries_data,
pot_value,
ext_clicks,
stats_store,
)
Works perfect until there.
Now, I would like to add the possibility of selecting a start date and an end date so I can request -eventually- more data. For that I created the callback below.
The idea is that after pressing on a button, a new request is made and the store gets filled with the new timeseries.
I thought that since the store is also an input of the plot_graph function, the graph was gonna get updated automatically. Unfortunately this does not work. The update_timeseries_values callback does not updates the Store. Do you know what I’m doing wrong?
@app.callback(
Output(ids.TIMESERIES_STORE, "data", allow_duplicate=True),
Input(ids.REQUEST_DATES_BUTTON, "n_clicks"),
[
State(ids.START_DATE_PICKER, "date"),
State(ids.END_DATE_PICKER, "date"),
State(ids.MODULE_STORE, "data"),
State(ids.TIMESERIES_STORE, "data"),
],
prevent_initial_call=True,
)
def update_timeseries_values(
n_clicks: int, start_pick, end_pick, module: str, timeseries_store_data: dict
):
Thank you in advance.