Cannot change multiple plots dataframe with dropdown menu

Hi,

I would like to show two time-series scatter plots in the same figure with a drop-down menu containing a list of countries. I’m able to update the first scatter plot but not the second and I can’t figure out why.

Does anyone know how to fix it, please?

Here is the script I’m using:

fig = make_subplots(specs=[[{“secondary_y”: True}]])

country = list_countries[0]
fig.add_trace(go.Scatter(x=pd.DataFrame(df[df[‘country’] == country].groupby(‘date’)[[‘idx1’,‘idx2’]]].sum()).reset_index().sort_values(by=‘date’).date,
y=pd.DataFrame(df[df[‘country’] == country].groupby(‘date’)[[‘idx1’,‘idx2’]]].sum()).reset_index().sort_values(by=‘date’).idx1,
line=dict(color=‘cyan’), visible=True))

fig.add_trace(go.Scatter(x=pd.DataFrame(df[df[‘country’] == country].groupby(‘date’)[[‘idx1’,‘idx2’]].sum()).reset_index().sort_values(by=‘date’).date,
y=pd.DataFrame(df[df[‘country’] == country].groupby(‘date’)[[‘idx1’,‘idx2’]]].sum()).reset_index().sort_values(by=‘date’).idx2,
line=dict(color=‘purple’), visible=True), secondary_y=True)
updatemenu=
buttons=

for c in list_countries:
buttons.append(dict(method=‘restyle’,
label=c,
visible=True,
args=[{‘y1’:[pd.DataFrame(df[df[‘country’] == c].groupby(‘date’)[[‘idx1’,‘idx2’]]].sum()).reset_index().sort_values(by=‘date’).idx1],
‘y2’:[pd.DataFrame(df[df[‘country’] == c].groupby(‘date’)[[‘idx1’,‘idx2’]]].sum()).reset_index().sort_values(by=‘date’).idx2],
‘x’:[pd.DataFrame(df[df[‘country’] == c].groupby(‘date’)[[‘idx1’,‘idx2’]]].sum()).reset_index().sort_values(by=‘date’).date],
‘type’:‘scatter’}, [0]],
)
)

updatemenu =
your_menu = dict()
updatemenu.append(your_menu)

updatemenu[0][‘buttons’] = buttons
updatemenu[0][‘direction’] = ‘down’
updatemenu[0][‘showactive’] = True

fig.update_layout(showlegend=False, updatemenus=updatemenu)

fig.show()