Hi, I am currently using Streamlit for a simple dashboard application. I want to display a temperature and speed value (changes continuously using random function). I have 2 tabs created using st.tabs() using st.empty() I’m refreshing the values it running fine. but the issue I’m facing when the value changes continuously in tab1 using st.metrics and when i click tab2 I’m unable to view tab2, I know it is because halted in tab1 while. if it is a radiobutton or selectbox no problem. for tab what I should do to both tabs with while running separately.
following is the code.
def tab_1():
Vstatusholder = st.empty()
while True:
temp_val = random.randint(25,40)
speed_val = random.randint(2500,3000)
with Vstatusholder.container():
c1, c2 = st.columns(2)
c1.metric("Temperature", temp_val, "%")
c2.metric("Speed", speed_val, "RPM")
t.sleep(2)
Vstatusholder.empty()
def tab_2():
Vholder = st.empty()
while True:
temp_val = random.randint(25,40)
speed_val = random.randint(2500,3000)
with Vstatusholder.container():
c1, c2 = st.columns(2)
c1.metric("Temperature", temp_val, "%")
c2.metric("Speed", speed_val, "RPM")
t.sleep(3)
Vholder.empty()
def main():
tab1, tab2 = st.tabs(["tab1", "tab2"])
with tab1:
tab_1()
with tab2:
tab_2()
if __name__ == "__main__":
st.set_page_config(page_title="Dashboard", layout="wide")
main()
Python version 3.10
streamlit latest version