Issue with asyncio run in streamlit

Hey,

I’m pretty sure we got this problem before when building a realtime monitoring solution, but I don’t clearly remember I’d have to go back into old code :confused:

I recall we added a rerun somewhere and maybe an empty, like:

import asyncio
import streamlit as st
from datetime import datetime

st.set_page_config(layout="wide")

st.markdown(
    """
    <style>
    .time {
        font-size: 130px !important;
        font-weight: 700 !important;
        color: #ec5953 !important;
    }
    </style>
    """,
    unsafe_allow_html=True
)

async def watch(t: st._DeltaGenerator):
    while True:
        t.markdown(
            f"""
            <p class="time">
                {str(datetime.now())}
            </p>
            """, unsafe_allow_html=True)
        await asyncio.sleep(1)
        st.experimental_rerun()  # <-- here

test = st.empty()

asyncio.run(watch(test))

Maybe that’ll help you a bit :stuck_out_tongue:

3 Likes