I am trying to make a variant of this example where the slider controls the v_line, but cant get it to work as expected. It returns:
IndexError: list assignment index out of range
This is my code:
import plotly.graph_objects as go
import numpy as np
# Create figure
fig = go.Figure()
# Add hline, one for each slider step
for step in np.arange(0, 5, 0.1):
fig.add_hline(step, visible=False,
name="𝜈 = " + str(step),
)
# Make 10th line visible
fig.layout["shapes"][10].visible = True
# Create and add slider
steps = []
for i in range(len(fig.layout["shapes"])):
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=10,
currentvalue={"prefix": "Frequency: "},
pad={"t": 50},
steps=steps
)]
fig.update_layout(
sliders=sliders
)
fig.show()