I am creating a dropdown list containing “weekly” and “monthly” using plotly graphing objects. I have added traces to plotly figure from 2 pandas dataframes - df_weekly and df_monthly. I want to display one trace when “weekly” is selected from the dropdown list and another trace when “monthly” is selected in the dropdown list. How can I achieve that?
fig = go.Figure()
# Add plot trace
fig.add_trace(
go.Scatter(x = df_weekly.TimeCreated,
y=df_weekly.total_calls_and_conf.values.tolist(),
name="total_calls_and_conf"))
fig.add_trace(
go.Scatter(x = df_monthly.TimeCreated,
y=df_monthly.total_calls_and_conf.values.tolist(),
name="total_calls_and_conf"))
# # Add dropdown
fig.update_layout(
updatemenus=[
dict(
buttons=list([
dict(
args=["type", "line"],
label="Weekly",
method="restyle",
),
dict(
args=["type", "line"],
label="Monthly",
method="restyle"
)
]),
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.1,
xanchor="left",
y=1.1,
yanchor="top"
),
]
)