When I execute the code block, the image that shows is that:
I understand why it is showing this image. The compiler is reading the data attribute from “fig” as a whole, but that
doesn’t makes sense. So I would like to show the first image of the slider by default. The way it is I need to drag the slider to see.
The code follows the template available in the Ploty tutorial page
# Create figure
fig = go.Figure()
# Add traces, one for each slider step
for step in range(1,len(top_10_marcas)):
fig.add_trace(
go.Bar(
x=top_10_marcas[:step],
y=top_10_2020_2021[top_10_2020_2021['Marca'].isin(top_10_marcas[:step])].loc['2020','GRP'].values
))
# Make 10th trace visible
# fig.data[-1].visible = True
# Create and add slider
steps = []
for i in range(len(fig.data)):
step = dict(
method="update",
args=[{"visible": [False] * len(fig.data)},
{"title": "Slider switched to step: " + str(i)}], # layout attribute
)
step["args"][0]["visible"][i] = True # Toggle i'th trace to "visible"
steps.append(step)
sliders = [dict(
active=0,
currentvalue={"prefix": "Frequency: "},
pad={"t": 100},
steps=steps
)]
fig.update_layout(
sliders=sliders
)
fig.show()