Clearing and redrawing graph on submit, in the same callback

I have a Dash UI to gather user input. When the user submits the form data (I have a Submit button), the values get sent to a Flask server (backend) via REST api, which in turn sends back an array of values. I display these values on the UI as a graph (dcc.Graph). The Submit button callback prepares a graph object and returns it to be displayed in a graph placeholder.

If I want to resubmit the form (with different input values), I’d like to clear the graph, and then redraw it based on the values returned by the backend. I’m unable to do this in the same callback function (can’t return two graph objects from the same callback). It seems I can’t have two callback functions with the same output either, so I can’t even put a CLEAR button on the UI.

Could you please suggest a way of clearing the graph before redrawing it?
Thanks.

Hi,

I imagine that your intention is to show the user that the graph is updating after pressing the button, right?

In that case, you could consider using dcc.Loading instead of updating the graph itself. Here is the link to the documentation:

https://dash.plotly.com/loading-states

1 Like

Hi jlfsjunior, your suggestion is much better than what I was thinking about initially. Many thanks, works like a charm!