✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Prevent Callbacks When Adding Elements To Dash Layout

Hi, first question on this forum.

So I’m making a Dash App which includes the functionality to press a button to add a particular element to the app layout (let’s call it the “button element”). The issue I’m having is that when I press that button, every callback attached to something in the button element is fired, both for the button element I just created and for every button element I had previously created. So if I have 3 callbacks to something in the button element, then the 5th time I press the button, the app is running 15 callbacks at once.

How can I prevent all these callbacks from firing every time I create a button element? I can provide more details if necessary.

(Edit: note that I’m using pattern-matching callbacks for this)


To disable triggering a callback when its outputs are first added to the page, pass prevent_initial_call=True when creating the callback, e.g.,

def some_callback(...):

This should work when using the pattern-matching syntax for outputs, inputs and/or states.

Thank you, this is exactly what I needed!