Hot-Reloading Issue

I am running streamlit locally - this is possibly a bug related to hot-reloading / development experience.

I am using

streamlit=1.30.0

With global config settings:

[server]
fileWatcherType = "auto"
runOnSave = true

Example code:

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.)

Iain

1 Like

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()
1 Like

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!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.