Dash Button which re-generates the data that populates dashboard

Hello,

I have dashboard which pulls budget data from a function which randomizes monthly expenses and income into a dataframe, and I then visualize that data in various graphs via dash layout.

The dash has a button that I would like to ‘re-generate’ this data, so the graphs would then visualize the newly randomly generated data (basically just re-run the functions again). However I am unsure on how to do this.

Here is the dash with the non-functioning ‘Generate’ button: http://analysis.pythonanywhere.com/

Any thoughts?

What you’re looking for are called Dash Callbacks: Basic Callbacks | Dash for Python Documentation | Plotly

Essentially, you’ll define a callback with your button’s click being the input and the charts/graphs you want to redraw as the Output. For the callback to work, you’ll wire it up to a function that will simply repopulate the same dataframe you originally used when the application starts. The return value of the function will be the set of charts you would redraw. The link above has code examples that’ll guide you towards your solution.