Creating Buttons within for loop

Hi everyone,

I have the following situation:

  • My base plot is a 3x2 subplot grid

  • I have a rather complicated data set which I have to iterate over, and there are 2 main lists which determine what will be seen, lets call them list1 and list2 and I have to iterate over each combination in order to get my data, like

    
    nrows, ncols = 3, 2
    
    fig = make_subplots(rows=nrows, cols=ncols)
    
    for l1 in list1:
    
        for l2 in list2:
    
            # some computation stuff happens here,
    
            # but the data needs to be broken down further
    
            # the computation yield 2 dataframes, lets call them
    
            # df1 and df2, which are similar in shape
    
            for i, c in enumerate(cs):
    
                for m in ms:
    
                    # first dataframe df1
    
                    if df1.shape[0] > 0:
    
                        # mask for m
    
                        m_mask = df1.loc[:, "m"] == m
    
                        # mask for s
    
                        s1_mask = df1.loc[:, "s"] == 1
    
                        s2_mask = df1.loc[:, "s"] == 2
    
                        # combine the masks
    
                        mask1 = m_mask & s1_mask
    
                        mask2 = m_mask & s2_mask
    
                        # x and y data for s1
    
                        x1 = df1.loc[:, l1][mask1]
    
                        y1 = df1.loc[:, c][mask1]
    
                        fig.add_trace(go.Scatter(x=x1, y=y1), row=i, col=1)
    
                        # x and y data for s2
    
                        x2 = kor.loc[:, l1][mask2]
    
                        y2 = kor.loc[:, c][mask2]
    
                        fig.add_trace(go.Scatter(x=x2, y=y2), row=i, col=1)
    
                    # second dataframe df2
    
                    if df2.shape[0] > 0:
    
                        # mask for m
    
                        m_mask = df2.loc[:, "m"] == m
    
                        # mask for s
    
                        s1_mask = df2.loc[:, "s"] == 1
    
                        s2_mask = df2.loc[:, "s"] == 2
    
                        # combine the masks
    
                        mask1 = m_mask & s1_mask
    
                        mask2 = m_mask & s2_mask
    
                        # x and y data for s1
    
                        x1 = df2.loc[:, l1][mask1]
    
                        y1 = df2.loc[:, c][mask1]
    
                        fig.add_trace(go.Scatter(x=x1, y=y1), row=i, col=2)
    
                        # x and y data for s2
    
                        x2 = kor.loc[:, l1][mask2]
    
                        y2 = kor.loc[:, c][mask2]
    
                        fig.add_trace(go.Scatter(x=x2, y=y2), row=i, col=2)
    
    
  • Within the 2 for loops, there are multiple statements of fig.add_trace(go.Scatter(...)), each of which plots a subset of my data

  • Since I want to make this interactively, I whish I could create some buttons which let me choose the corresponding combination from list1 and list2

Is there any possibility that I can achieve this?

I tried looking at so many different drop down menu tutorials but neither of them worked for my use case.

In case there are any misunderstanding, I am happy to clear them up!

All the Best,

J