So i have a multipage dash app which shares the same dcc elements to fabricate filters for mi database queries. Since not all the pages use all filters (and some dropdowns hide some elements dynamically) i was wondering if there is a way to remove the callbacks that exists in the current page to avoid having unnecesary callbacks in the page.
did you ever figure this out? having a similar problem.
sadly no, we still keep them up
Callbacks are created with the app object and cannot be removed or added at a later stage. What you can do on the other hand is to implement a custom logic inside the callback to take care of the different cases. E.g. the callback could take as argument the value of a dcc.Location
element and do something different depending on the url.
Altough this solution works, its far from ideal.
My application is structured in a way where i have a .py containing various custom dbc.html objects with set ids that i thought could be reused accross diferent pages. When i tried re-using them i started having callbacks from other pages getting fired.
Just like OP, my first thoght was: “ok, how i disable this callbacks”.
Since that is not possible… I have to “to implement a custom logic inside the callback”.
There are two problems with that:
- My callbacks have various inputs/outputs, adding another state/input won’t solve the problem because other objects required for this callbacks wont be available in the page.
- My previous page has 20+ callback functions and i would have to manually edit every single callback. Its just not a great use of time.
Okay, it is ugly, but it is quite straightforward. Since i will use some objects i decided to parameterize the objects internal items ids, because callbacks are bounded to each object id. Changing them will prevent previously defined callbacks from firing…
This bothers me because id concept in html is chained to each individual html file, and, when using flask, for example, using same ids in different routes/pages doens’t change much the way you have to structure your backend.