Is it possible to add more graph components to a Div upon clicking a button? I have in mind a column layout that starts empty. The user then can choose to add new graph via buttons or dropdowns (e.g., to choose the graph type). Is it possibly to implement this functionality? This seems to require changing html components rather than core components. Are callbacks limited to core components? If such limitations exist what do you recommend to get around them?
Callbacks can be added to any component: Core, HTML, or custom. You can modify the children of a div by adding a callback with
Output('my-div', 'children') as the specified output, and then the value of your dropdowns etc. as the inputs.
@app.callback(Output('my-div', 'children'), [Input('my-dropdown', 'value')])
# Some code to choose the new child
child = my_choice_function(value)
On a related note, if there are button presses to create an additional graph, what is the correct way to handle them? I read a bit around the forum, and it seems that there is no way of creating new callbacks after the app is running. This means that all callbacks have to created upfront. How does this fact affect the way I go about designing the layout? Does that mean that I’m mostly stuck with use cases where a fixed layout is created and then all the interactivity comes from updating the state of the elements of this fixed layout? Let us say that I want to not only create a new graph with new callbacks, but also delete it. Would this be possible? This may require creating new html elements on the fly. Thanks!
I’m trying to do something like this too. I want to add/remove graphs when clicking on some buttons. Did you find any solution to this?
Hi @Episkiliski and welcome to the Dash community
This can be done with pattern matching callbacks. See more information here Pattern-Matching Callbacks | Dash for Python Documentation | Plotly
Also this post has an example of adding and deleting graphs - Pattern call-backs regarding adding dynamic graphs