import streamlit as st
import time
import pandas as pd
import numpy as np
st.title("Example Page")
# generate dataframe of 24 1s
data = np.ones(24)
data = pd.DataFrame(data, columns=["data"])
line_container = st.empty()
while True:
with line_container:
st.line_chart(data)
time.sleep(5)
data += 1
If you edit a component, e.g. the title of the page and hit save the page does not rerun and render the changed title.
My current workaround:
hit the stop button in the web-browser (app running as data updating in while loop)
make a change
press save
If I follow these steps all changes are then recognised and reruns are triggered on save (even when the app is running.)
I’ve played around with other config settings but they make the issue persist (i.e. the workaround no longer works.)
This is likely due to the infinite while loopwhich never finishes, and so the streamlit app never finished running through a single iteration of a page, and so won’t respond to other changes.
If you remove the while loop, it should work fine. If you need to rerun something every 5 seconds, you might consider using the new experimental fragment ⚡️ Launched in 1.33: st.experimental_fragment
Here’s a version of your app with st.experimental_fragment, and it works fine with hot reloading if you change something on the page.
import streamlit as st
import pandas as pd
import numpy as np
st.title("Example Page")
if "data" not in st.session_state:
st.session_state.data = pd.DataFrame(np.ones(24), columns=["data"])
line_container = st.empty()
@st.experimental_fragment(run_every=5)
def update_line():
with line_container:
st.line_chart(st.session_state["data"])
st.session_state["data"] += 1
update_line()
The hot-reloading will work if you stop the app once, make a change and hit save. All changes from this point on are recognised (even during the while loop.)
That being said - I’ll have a play around with the experimental_fragement functionality. I much prefer the sound of it than the infinite while loop!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
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.
Performance cookies
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.
Functional cookies
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.
Targeting cookies
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.