Plotly Chart with multiple inputs

Hi I am new to Plotly, I am trying to create one chart with two dropdowns (Country and Year), where the Chart will change if the Country or Year input changes. However by running the code below it gives a blank chart, I’ve done a lot of googling, but still no idea what went wrong.

html.Label(
children=‘Select countries:’
),
dcc.Dropdown(
id=‘country-dropdown’,
style={‘color’: dropdown_style[‘text’]},
options=[{‘label’: i, ‘value’: i} for i in sorted(df.Country.unique())],
value=[‘Malaysia’,‘Indonesia’,‘Brunei’,‘Philippines’,‘Singapore’,‘Thailand’],
multi=True
),
html.Label(
children=‘Select Year:’
),
dcc.Dropdown(
id=‘Year-dropdown’,
style={‘color’: dropdown_style[‘text’]},
options=[{‘label’: i, ‘value’: i} for i in sorted(df.Year.unique())],
value=[‘2019’,‘2020’,‘2021’,‘2022’],
multi=True
)
]
)

@app.callback(Output(component_id=‘graph-output’, component_property=‘figure’),
[Input(component_id=(‘country-dropdown’), component_property=‘value’)],[Input(component_id=(‘Year-dropdown’), component_property=‘value’)],
prevent_initial_call=False
)

def update_graph(input_value1,input_value2):
if len(input_value1) > 0 or len(input_value2) > 0:
updated_df = df[(df[‘Country’]==input_value1) & (df[‘Year’]==input_value2)]
fig = px.bar(updated_df,x=“Date”, color=“Country”, title=“M-o-M Trend”)
fig.update_layout(barmode=‘stack’, yaxis={‘categoryorder’: ‘total ascending’})
return fig
elif len(input_value1) == 0:
raise dash.exceptions.PreventUpdate

If multi = True, I think you should change from updated_df = df[(df[‘Country’]==input_value1) & (df[‘Year’]==input_value2)] to updated_df = df[(df[‘Country’].isin(input_value1)) & (df[‘Year’].isin(input_value2))]

Works!! TQVM!

Thank you, so please mark my reply as solution.