In cases like these, you can “store” the output in a hidden DIV as JSON and then use that result in the next callbacks. See Add reactive expressions / blocks · Issue #49 · plotly/dash · GitHub for more details.
The main thing is that the Dash app backend’s state is read-only. The real “state” of the app is inside the front-end in the user’s web browser. Dash apps can’t modify global variables in the Python context because those modifications
- wouldn’t scale across multiple python processes (each with their own memory). when dash apps are deployed, they run on multiple processes.
- would need to be stored separately for each user, increasing the memory requirements of the backend considerably. instead, we store the state in the front-end in the user’s client.
If you want a callback to trigger a calculation, you have two options:
- store the results of the calculation in a hidden div as mentioned above
- perform the calculation and then set the output to be a hidden div and just return
None
or even raise anException
- perform the calculations one-time on app start
- perform the calcuations on page-load by setting
app.layout
to a function (as here: Live Updates | Dash for Python Documentation | Plotly)