I'm writing a small script to plot material data using plotly, I tried to use a dropdown to select which column of my dataframe to display. I can do this by defining the columns one by one but the dataframe will change in size so I wanted to make it flexible.
I've tried a few things and got to this;
for i in df.columns:
fig = go.Figure()
fig.add_trace(go.Scatter(x=df.index, y=df[i]))
fig.update_layout(
updatemenus=[
go.layout.Updatemenu(
buttons=list([
dict(
args=["values", i],
label=i,
method="update"
),
]),
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.1,
xanchor="left",
y=1.1,
yanchor="top"
),
]
)
fig.update_layout(
annotations=[
go.layout.Annotation(text="Material:", showarrow=False,
x=0, y=1.085, yref="paper", align="left")
]
)
fig.show()
The chart shows the final column of the df, while dropdown only holds the last column header?
My data looks something like this, where i is the index, the chart and dropdown show column 'G';
i A B C D E F G
1 8 2 4 5 4 9 7
2 5 3 7 7 6 7 3
3 7 4 9 3 7 4 6
4 3 9 3 6 3 3 4
5 1 7 6 9 9 1 9

