Change datasource based on toggler

Hi All,

I want to have a look into the possibility of switching a dataframe based on a toggle at the top of my app, so for example, if you pick option A then my DF var would be df=SourceA and if you pick option B then the DF var would be df=SourceB

Now I know it is very straightforward to do with an if statement in the individual call backs to perhaps reference a varying column on the same dataframe containing either source A or Source B data, however, I have 36000 lines of callbacks in my app that it would take me an absolute age to go and add 1 additional if statement to each of them to read a new column

Really hoping for a solution where the toggler can swap the data source and my DataFrame, columns and callbacks can remain the same just with this option to swap the actual dataset

Thanks!

Hi,

Just to clarify your problem: are you saying that it is difficult to add a callback to toggle the data because you have hardcoded statements in other callbacks that works specifically with one of the dataframes, but not the other?

If that is the case, and you already have a lot of callbacks defined for each dataframe specifically, you could consider having a two-page app (one for each dataframe), where each page has its own set of callbacks (examples here), and the toggle is responsible for switching from one page to another.

Personally I am not a big fan of the approach above (what if you want 3 dataframes… and then 4…?) and I would consider some refactoring if the 36000 lines are not a figure of speech… :slightly_smiling_face:

So basically the toggle at the top of the page would need to display the same data but calculated differently, so for example data frame A stores in Column A the value of 10 but data frame B in Column A stores the value of 15 - so its 2 data frames that are replicas in terms of column names but with varying values in the columns, so I wanted the toggler to flip between data frames - your idea of the multipage is actually genius even though id prefer not to use it it is a very viable option here.

And yes the 36000 really is not a figure of speech and has been refactored as best as it can be, the web app has some crazy large dynamic filters that feed off of each other to display varying figures :sweat_smile:

Ok, I might have misunderstood your problem, and it is still not clear to me.

If the columns are the same and the calculations in the callback are the same for the two datasets, then it should be just a matter of using the toggle value to point at the selected dataframe. Then the way to go depends on where you are loading these dataframes (in the global scope, or in a Store) and how big they are…