Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

How to update data with multiple filters

Sorry for asking so many questions, but I am very new to dash and apps in general, so I run into constant issues, that i cannot find any solution for my self:
So what I am trying to do is the following:
I upload data
I store the data in global variable as well as in a hidden div as explained in (Part 5. Sharing Data Between Callbacks | Dash for Python Documentation | Plotly)
I have a slider to select a filtering method for the data
I want to update the data in the hidden div with the filtering method
I plot the data, that I retrieve from the hidden div.

Now I ran into the issue that, as explained here (Multiple outputs duplicate issure) one cannot have the same output across multiple callbacks.
I guess it makes sense, because otherwise it would not be clear which value the output actually has at any given time, but I do not know how else to do what I want to achieve.
Sure, with one filtering method I could do the following:

I upload data
I store the data in global variable as well as in a hidden div
I have a slider to select a filtering method for the data
I store the filtered data in a hidden div
I plot the data, that I retrieve from the hidden div.

But what if I have more than one filtering method/operation I perform on my data?
Would I need to have a whole long workaround like:
I upload data
I store the data in global variable
I have a slider to select a filtering method for the data
I store the filtered data in a hidden div
I retrieve the data from the hidden div and filter it by a second method, I store the data in a different hidden div
I have a selector for which hidden div the data should be retrieved from (which would require 4 data storages,
unfiltered, filtered1, filtered2, filtered 1+2. This would get extremely tedious with increasing amount of filters.
I make a plot from what data I have selected.

Or is there a more straight forward method to do this?

You can concatenate multiple filters operations. See https://dash.plot.ly/datatable/style, specifically the “Conditional Formatting - Highlighting Cells” section.

You can pickle the uploaded data and store it in a file, then load it before applying a filter. The you pickle the filtered data and rewrite the file, and so on…

I recently ran into a similar problem where I had to update an object from different callbacks without storing the object in a global variable. The pickling method worked for me

Mhh, could be an option for expensive filters.
I kind of think though we should have the option to use the same output in multiple callbacks.
Sure it can mess up your app if you use it wrongly, but that can happen with a lot of things.
I recently ran into an issue, where I wanted to display images based on hoverdata.

I first get the paths to the images and store them in a dictionary.
Upon hovering I then base64 encode the image and display it.
It works but is a bit slow. So I thought I could update the dictionary with the base64 encoded files instead of the file paths, so next time one is hovering over the same data, the display is smoother.
Well, can’t do that of course, because I cannot reuse the output.
Will this ever become an option, or is there a reason why we will never be able to reuse an output in multiple callbacks?

Just ran into another inconvenience because of this:
I have multiple graphs in my app, wanted to store them in a dictionary, so they can be faster retrieved once they are created.
Works perfectly well, however I have filter options for the data in my app, so I cannot change the filters anymore once the graph is created.
The easiest fix for this would be a callback that takes all filters as inputs and simply replaces the dictionary with an empty one, whenever a filter is changed. But again, this is not possible because of the duplicate output issue.
So instead of this super simply intuitive solution I will need to implement another checkbox to ask the user, if he wants to reuse a graph or not, decreasing usability and intuitiveness.
Reusing Outputs would really be great improvement in my opinion.

1 Like

I agree with @snizl… any arguments to the contrary?