Update in a loop

Hello,
I’m new to plotly and I don’t know how to update a chart. Here’s my code :

i = 0
while True:
    last_prices = prices[:1+i]
    fig = go.Figure(go.Candlestick(x=last_prices["Time"], open=last_prices["open"], high=last_prices["high"], low=last_prices["low"], close=last_prices["close"]))
    time.sleep(2)
    fig.show()
    i += 1

This code open a new tab every 2 seconds, how can I update the same graph (without dash) ?

Hey @Lukkyz ,

Welcome to the community.

Inside that loop you are constantly creating a new figure because of the this line:

fig = go.Figure(go.Candlestick(x=last_prices["Time"], open=last_prices["open"], high=last_prices["high"], low=last_prices["low"], close=last_prices["close"]))

This page might help you to understand the basics:

https://plotly.com/python/creating-and-updating-figures/#updating-figures

Have a nice day.

Thank you :slight_smile:
In the doc I don’t find anything that can make this possible.
Here’s the code :

fig = go.Figure()
fig.show()
for i in range(len(prices)):
    fig.add_trace(go.Candlestick(
        x=(prices.index.get_level_values("Time")[i],),
        open=(prices["open"][i],),
        high=(prices["high"][i],),
        low=(prices["low"][i],),
        close=(prices["close"][i],)
    ))

It open tab with nothing and if I add fig.showat the end of the loop, it will same as the previous code