Dash - Multi level filtering and data sharing in chained callbacks

Hi,

I have a problem regarding filtering the data in multiple stages and rendering the filtered dataframes.
To put things as simply as possible I have:

  • 2 range based filters that span from 0 - 100
  • Individual graph dropdown selections for selecting the X-axis categories
  • Button selections for selecting segmentation types for the data

The problem:

  • Currently i have a single callback function which takes in as input all of these interactive components and then recalculates everything for the graphs to be drawn.
    This means that if one of the range filters was selected - all the dataframes are recalculated based on those filters and then it recalculates for the individual graph dropdown selections and looks for button selections
  • All of the dataframes have to be recalculated for every single interactive component even if the change didn’t happen for the range sliders, but for example only a dropdown was selected to change a single graph’s X-axis categories

Attempted solution:

  • https://dash.plot.ly/sharing-data-between-callbacks Example 3 is something that seems to address this problem of only computing the large data once and then passing it to all the individual callback functions for individual graphs to use this computed dataset without having to recalculate.
  • This solution doesn’t work when you have something like a range slider (or even worse - multiple range sliders) which means that the different possibilities of input values are insanely large (lets consider it infinite) because you cannot cache every single possible filtering variation. The 4 datasets are roughly 100MB combined.

Is there a way to share data to other callbacks without having to cache it in hope that sometime in the future the same filtering combination will be applied and the dataframes will just be returned from memory instead of recalculating?

Thanks for any tips regarding this, it’s making my head explode after multiple days of trial and error :frowning:

Bruno

Could you please share a minimal and standalone code reproducing your problem (for example with synthetic data)? It would be easier to suggest solutions. Also, if you have this big callbacks with many inputs and you want to apply different rules depending on which input has been fired, you can use dash.callback_context as described in https://dash.plot.ly/faqs ( Q: How do I determine which Input has changed?).

three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online