Hello everyone! I hope you can help me solve this problem.
Imagine I have this app
import time
import streamlit as st
import streamlit.report_thread as ReportThread
from threading import Thread
SLEEP_TIME = 0.01
ctx = ReportThread.get_report_ctx()
def print_numbers(thread_id, empty):
ReportThread.add_report_ctx(None, ctx)
output = st.text("")
n = 0
while n < 1000:
n += 1
output.text("Thread %s: %s" % (thread_id, n))
time.sleep(SLEEP_TIME)
empty.write(f'Hello {n}')
empty = st.empty()
if st.button('Push'):
thread = Thread(target=print_numbers, args=(2, empty))
thread.start()
st.subheader('Something')
st.text_input('Write something')
st.selectbox('Select something', range(10))
The issue here is not the threading itself because it actually runs without problems in the background. However, I would like that empty.write(f'Hello {n}')
prints in every iteration to have a notion of the current state of the loop. The problem is that this just updates once and the only way that I have seen that it updates again is when I do something in the app that refreshes the page, but it just updates that time. In other words, the empty.write(f'Hello {n}')
stays in a same value.
NOTE: Part of this code has taken from here I just added some features to make it more similar to my problem.
Thank you!!