I have a dashboard with a dcc.DatePickerRange whose default value is last month. So for example, on page load:
start_date = “2020-06-01”
end_date = “2020-06-30”
When start_date or end_date change, it triggers a query whose execution time is proportional to the number of days between start_date and end_date.
If a user is interested in, say, the June 2015 data, they will first update start_date to “2015-06-01”, and, by the time they change end_date to “2015-06-30”, the query for June 2015 to June 2020 will have been fired and they will have to wait for this lenghty query to finish. Only then, will the real June-2015-only query run and the figure be updated.
If I could cancel the running callback and start a new one when end_date is updated, that would solve my problem.
Is there any way to do that?
layout = html.Div(
children=[dcc.DatePickerRange(id="date-range",), dcc.Graph(id="figure"),]
)
@app.callback(
Output("figure", "figure"),
[Input("date-range", "start_date"), Input("date-range", "end_date")],
)
def update_figure(start_date, end_date):
data = run_lenghty_query(start_date, end_date)
figure = make_figure_from_data(data)
return figure
1 post - 1 participant