✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

How to check if a State has changed in Dash Callback?

Hello! I have a callback which has a button for Input and other variables as States

@app.callback(
dash.dependencies.Output(‘slider’, ‘value’),
[dash.dependencies.Input(‘submit-button’, ‘n_clicks’)],
[dash.dependencies.State(‘dropdown’, ‘value’),
dash.dependencies.State(‘slider’, ‘value’),]
)
def update_slider(drop_val, slider_oldval)

@app.callback(
dash.dependencies.Output(‘fig’, 'figure),
[dash.dependencies.Input(‘submit-button’, ‘n_clicks’)],
[dash.dependencies.State(‘dropdown’, ‘value’),
dash.dependencies.State(‘slider’, ‘value’)]
)
def update_figure(drop_val, slid_val)

‘slider’ depends on ‘dropdown’ and whenever I click on ‘submit-button’, the last callback gets the updated value of ‘dropdown’ and an old value of ‘slider’. An important issue is that ‘slider’ is updated using a previous value. I’m not sure how to do it to get the most updated value of ‘slider’ before this callback is executed. I would really appreciate your advises on this issue.

Thanks in advance.

Hi aprodel,

Not sure I understand. When the callback fires, it should use the latest value of the dropdown and slider as shown on the page. Can you provide more info on the “old value of ‘slider’”?

Thanks for the response allenite.

I changed a little my question.

In order to update the slider value (in update_slider function), I have to use its previous value and the dropdown value… And to update the figure (in update_figure), I need both values updated, dropdown and slider. But in the execution, after I change the dropdown, the callback update_figure receives the updated value of dropdown, and the slider value corresponding computed with the previous dropdown.

I don’t know how to check if the states are all updated when firing the update_figure callback. I read something about a dash.callback_context, but not sure how to use it or if it will do.