Best Practice for using one df to create another df based on filters applied


Fairly new to using Dash. I’ve gone through the user guides and basic tutorials provided as well as finished a demo project to create a simple dashboard that plots stock price changes over time using a single drop down menu to filter stocks on/off.

I’m now trying to build a more custom dashboard for a data set of mine and looking essentially to create a heat map using a csv file that I read into a pandas data frame. However, I need to apply some python logic (aggregation/sums) to the original data frame A in order to produce data frame B which is used in the heat map and I hope that any time the filters in the dashboard are updated - it will trigger and re-create data frame B.

What is the best way to handle this or things to keep in mind? I obviously could load in just data frame B but I’d rather maintain the original data frame A as it contains more information that I need to present and then it wouldn’t be as easy to filter things off and on. Any input or advice is appreciated.

Welcome to Dash @bicachu

What I usually do is import the original csv data into a Pandas dataframe at the beginning, before I start the app layout.
Then, inside the callback function, I make a copy of dataframe A like this:

dff = df.cooy()

And based on user input, I filter the dff to return the output I need

1 Like

@adamschroeder thank you! I appreciate the input, seems to do the job.