Introducing pattern-matching callbacks
Mastering this feature, and here we are dealing with a truly new feature, will allow you to take your apps to a new level of interactivity and power. The most important feature of this capability is that it allows us to handle the interactivity of components that didn't exist before. As we've done so far, when we allowed users to create new charts by clicking a button, those components did not exist before in the app. The more interesting thing is that the callback function that handles them all is as simple as any other callback that takes values from a dropdown and produces a chart. The trick is in slightly changing the id
attribute of our components.
So far, we have set the id
attributes as strings, and the only requirement was that they be unique. We will now introduce a new way of creating this attribute, which is by using dictionaries. Let's first take a look at the end goal, then modify the layout, the callbacks, and finally...