Which input gets called on initialization in a multi-input callback?

Hello!

Trying to understand what goes under the hood here.
I have a callback function that relies on two inputs (ButtonA and ButtonB) and a state of a div component. When I initialize the app- which button would trigger the callback? I seem to always get ButtonB (using dash callback context) but I don’t know why. It would be very helpful to know which input would get called.

Thanks,

Jon

Could you try upgrading your version of Dash? In 1.11.0 (📣 Dash v1.11.0 Release - Introducing Pattern-Matching Callbacks) we cleaned up some of this logic and I believe that callback context should be empty when two components are rendered at the same time.

1 Like

Thanks for the response!
I updated my dash version to the latest Dash release (1.13.3), though the problem still persists- callback context still yields that ButtonB triggered the callback.

If you don’t need the initial callback, you can use the prevent_initial_callbacks flag to avoid them. I know this is not a direct answer to your question, but in most cases i find that the initial callback are more hassle than useful, so I just wanted to share the option (it was introduced in Dash 1.12.0) :blush:

1 Like

Thanks Emil. That’s actually very helpful- I added that to my callback, since the component I’m trying to add already has a default value.

Funnily enough I don’t think it worked, or at least worked as I expected? The callback function was activated nonetheless, which I gather from the fact that the print statement I have at the start of the callback showed up on my terminal. It also said that ButtonB triggered the callback. Is my understanding of the prevent_initial_callback accurate (i.e. it shouldn’t have been called in the first place?) or does it react similarly to raise PreventUpdate, in which the callback activates but doesn’t update the output?

Thanks

Jon

@Emil
@chriddyp
Apologies! Disregard what I said about the prevent_callback or the callback context not working. I’m not sure why exactly, since I restarted the script once already on a new terminal window after updating dash, but when I opened a new terminal window and reran my script for the 3rd time it worked. The print statement is no longer visible likely indicating that the callback was not activated.

Thank you for your help! Still running checks but I think that should take care of it!

Jon