I have a dashboard with live data, so I am inclined to have a while loop with time.sleeps in it. However, while the app is sleeping, input from the app is unresponsive (e.g. if the user wants to add something to the dashboard from a sidebar form). This is the underlying problem I’m trying to solve.
To do that, I tried updating the dashboard from a different thread, but it seems like it only kind of works or doesn’t work. Example:
import streamlit as st
from threading import Thread
from streamlit.runtime.scriptrunner import add_script_run_ctx
import time
def do_stuff():
st.write("Start")
count = 0
while True:
st.write(count)
time.sleep(5)
print(count)
count += 1
t = Thread(target=do_stuff, daemon=True)
add_script_run_ctx(t)
t.start()
Terminal prints out:
But the website is blank. If I reload the website, it shows this:
Further reloads don’t do anything.
Streamlit version 1.13.0