Hi,
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?
Thanks
Hi,
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?
Thanks
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)
chart.add_rows(new_rows)
progress_bar.progress(i)
last_rows = new_rows
time.sleep(0.05)
progress_bar.empty()
# 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.
st.button("Re-run")
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.
Hi Randy,
Sorry for the late reply.
I tried using add_rows but with no success.
I have been using plotly_chart graph_objects for drawing OHLC charts for stock tickers.
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 am not sure how I can use st.add_rows() in this situation.
Can you please help me with this?
Thanks
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.