I always felt that allow_duplicate was an option to use with some caution.
But didn’t know how to explain. Today I was inspired from a question on the forum to investigate this further.
In the article, I explore one bad consequence of using allow_duplicates=True, and how to mitigate it.
The article is about callback design, sequential callbacks and a relevant use case of Patch().
I hope it will open the discussion to some callback design strategies.
Let me know what you think about it!
I believe that you’ve made a strawman argument by using something like this. It is more efficient to use the values as a state and a submit button. XD
The power of allow_duplicates is allowing the same output to be targeted from different things in the app, things that wouldn’t be entered at the same time or even on the same screen. For example, sending notifications to a single div container from multiple pages or buttons.
Coming from front end, I prefer the granulated control of set_props and allow_duplicates because it gives more targeted control over the elements.
To elaborate, it was quite confusing and ridiculous to have an app that kept growing for inputs and trying to keep the notifications separate when they were all in one callback. Even using pattern-matching it was a beast.
I do agree with you. It’s a very good thing that allow_duplicates exist, for some cases.
However, I think the callback normal behavior (an output updated by only one callback) is a good idea to enforce a good & maintainable logic. Just like circular dependencies, were forbidden at first, and now possible in some ways.
Or “suppress_callback_exceptions”, which is certainly useful but error-prone.
I think it’s something “to use with caution”. Especially for beginners.
For those in the thread, maybe there’s some opportunity here to refine our documentation on duplicate callback outputs (Duplicate Callback Outputs | Dash for Python Documentation | Plotly). I’m happy to provide feedback to the team – we have a few examples of when/why to use duplicate callback outputs but could certainly change or improve them!
Actually, now that there are so many advanced callbacks, it would be great to have an overview section describing the purpose of the different callbacks and when to use them.
Maybe in fact “Advanced callbacks” is a bit of a misnomer and discourages use; many of these patterns are applicable even to “simple” apps. Definitely IA that could be improved.