Help with callback data being passed from one tab to another (dropdwon and Tabs)

Hello,

My app is for plotting lots of data from different category more of an excel sheets but not that sophisticated.

I have four sheets represented by the Tabs and two dropdown as seen in the picture below:

Let me explain how it works:
If I am on Sheet 1, the dropdown labelled as Field(1) will have some data of different field depending on the data.
and the lower dropdown with plots will contain different plots available on Sheet 1 to be plotted.

So, if you select a plot or more than one plot as it is multiselect, the app will plot them for the field you selected in first dropdown.

Now for each sheet, there are different fields and different plots.

So, I have been able to do this based on the data and the plots selected.

But when I change a tab, lets say from Sheet 1 to Sheet 2 I encountered an error which is due to the fact that the plots in Sheet 1 is being passed to Sheet 2 and Sheet 2 doesn’t have those plots. How can I make it such that when I change a tab to Sheet 2 for example, the dropdown will be empty or if a plot was already plotted, it will show those. And also when I go back to Sheet 1, the plots that was plotted before will be there, preventing passing of the plots from Sheet 2 to 1 or vice versa?

This is the code that is helping me to update tab content:

@app.callback(
    [
        Output('tab-content', 'children'),
    ],
    [
        Input('tabs', 'active_tab'),
        Input('field-selctd-dpdn', 'value'),
        Input('figs-to-plot', 'value'),
    ]
)
def update_content(sheet, field_selected, figs_to_plots):
    print('enter update content')
    plots = []
    print("Figures to plot: ", figs_to_plots)
    if field_selected == '' or len(figs_to_plots) == 0:
        return defualt_content
    else:
        data = get_data(sheet, field_selected)
        global field_plots
        field_plots = field_plots + list(set(figs_to_plots)-set(field_plots))
        for fig in field_plots:
            plot = create_plot(data, fig)
            plots.append(plot)
        plots = dbc.Row(plots)
        return [plots]

I wrote out the more complicated solution below first, but it sounds like you should have one set of dropdowns within each sheet, so they have separate states.

Alternatively:

I think you can have a callback with Output('field-selctd-dpdn', 'value') whenever you change tabs, setting it to a previously selected value value for that tab (stored in a dict in a dcc.Store, one key for each tab), or the null value if one hasn’t been selected before. Then a separate callback takes the dropdown value as input and creates the plots. I’m not sure if you can have Input('tabs', 'active_tab') in this second callback, I forget the rules about multiple Input/Outputs, but if you can’t, you can have the first callback increment a dummy value in a Store and have that as an input for the second callback with State('tabs', 'active_tab'), so that it triggers when you change the active tab.

Thanks but I tried having an output with Output('field-selctd-dpdn', 'value') but it throws an error that it is expecting a value of length one.
Even though the dropdown has multi=True.

Which complicated solution are you referring to?

The complicated solution is the last paragraph.

Ok, thanks but it is giving errors when I try to assign the dropdown value.