Incremental display of OHLC plot


I am displaying Stock ticker plots from my database in (near) real time. However, each time I need to Rerun to display the latest data. How can I have an incremental update of the OHLC plot every minute?


1 Like

Hi @bhawmik -

If you check out the streamlit hello demo, we have an example of continuously updating a plot. The code snippet looks as follows:

import time
import numpy as np

progress_bar = st.sidebar.progress(0)
status_text = st.sidebar.empty()
last_rows = np.random.randn(1, 1)
chart = st.line_chart(last_rows)

for i in range(1, 101):
    new_rows = last_rows[-1, :] + np.random.randn(5, 1).cumsum(axis=0)
    status_text.text("%i%% Complete" % i)
    last_rows = new_rows


# Streamlit widgets automatically run the script from top to bottom. Since
# this button is not connected to any other logic, it just causes a plain
# rerun.

The most important part of the code is chart.add_rows(new_rows), which adds data to the chart, forcing it to re-render. At the end of the loop you can see time.sleep(0.05); for your case, where you want an update for a long period of time, you could use a non-terminating while loop and/or create an on/off button to start the continuously updating chart.