Block slider sliding automatically on plotly

Viewed 177

In python3 I wrote a code to generate scatter plot graph using plotly and it has a slider to go through the different dates without changing graphs which is very useful.

However, when I open my graph the slider automatically starts slidding and going through the different dates.It there a possible way to block this option? In other words, is there a way to not allow my graph to automatically start the slider when I open it ?

Here is my code, I tried to put a very high duration but it did not change anything:

data = pd.read_csv('/homeResult-'+str(filename)+'.csv')
data['price'] = data['price'].astype(int)
fig = px.scatter(data, x = "model", y = "price", color="competitor", hover_data=['Discount'], animation_frame="date")
fig.update_layout(
    title=str(filename).replace('.csv', ''),
    yaxis_title="Price (€)",
    font=dict(
        size=12,
        color="#7f7f7f"
    )
)
#fig.update_layout(margin=dict(l=20, r=20, t=20, b=20),paper_bgcolor="LightSteelBlue")
fig['layout']['updatemenus'][0]['pad']['t'] = 180
fig['layout']['sliders'][0]['pad']['t'] = 200
fig.update_layout(transition = {'duration': 0})
fig.write_html("/homevisualisation/Viz-"+str(filename)+".html")

This is the slider I am talking about :

enter image description here

1 Answers

There is an auto_play parameter that plotly includes on export to HTML. That should fix your issue!

fig.write_html("/homevisualisation/Viz-"+str(filename)+".html", auto_play=False)

If you are curious on the workings of the argument, check out https://github.com/plotly/plotly.py/issues/1496 and https://github.com/plotly/plotly.py/pull/1503

Also, there are transition and frame durations. The transition duration is the length of the transition and the frame duration is the length of the frame.

Related