โœŠ๐Ÿฟ Black Lives Matter. Please consider donating to Black Girls Code today.
๐Ÿ‡ Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Dash multi-dependencies on callbacks

There are three elements in my app: A, B and C. Callback 1 takes A and update B, while Callback 2 takes A and B and then update C. When A is changed, I want Callback 1 to be called first. And only after B is updated (and the default value is changed), Callback 2 is called to update C. What happens now is that, when A is changed, Callback 1 and 2 are fired at the same time, and Callback 2 is using the old value of B. I tried to set B as a State instead of an Input in Callback 2, this solves the previous issue that B is stale. But the problem of this is when A is changed, C is no longer updated.

Is there any way to solve this? Thanks in advance.

Since changing A changes B you should update both B and C in the same callback.

@app.callback(
    [Output('B', 'value'), Output('C', 'value')],
    [Input('A', 'value')]
)
def update_values(A):
    B = some_function(A)
    C = some_other_function(A, B)
    return [B, C]
1 Like

This wonโ€™t work because when B is changed, I want C changed as well. However I canโ€™t register another callback function on C given B as an input.