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