OHLC Candlestick refresh/streaming display

I have been using plotly_chart graph_objects for drawing OHLC charts for stock tickers. I can draw a static chart using something like below:

Here is a section of my code:

import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Candlestick(x=dataf[‘DateTime’], open=dataf[‘Open’], high=dataf[‘High’], low=dataf[‘Low’], close=dataf[‘Close’]) )

st.plotly_chart(fig)

This correctly draws my OHLC graph but I want it to refresh with each new data arriving every minute.
I understand streamlit add_rows can be used to auto refresh at a give interval. However I am not sure how I can use st.add_rows() in this situation, especially with plotly graph_objects.

Is graph_objects/plotly not supported by add_rows?

1 Like

Hello,

look at the question I asked regarding ploting inside a loop and the answer that helped me : Refresh graph/datatable inside loop

The trick is to declare first pl = st.empty() and then have pl.plotly_chart used at the init and/or inside the loop. It won’t “refresh” the graph but draw a new one with all the values.

Hope it can help. :slight_smile:

Vinivici