Skip to content

Instantly share code, notes, and snippets.

@asehmi
Created April 19, 2022 18:03
Show Gist options
  • Select an option

  • Save asehmi/19637d813a576ac4fb6cfe6191f7a516 to your computer and use it in GitHub Desktop.

Select an option

Save asehmi/19637d813a576ac4fb6cfe6191f7a516 to your computer and use it in GitHub Desktop.
Using asyncio in Streamlit
import asyncio
import streamlit as st
from datetime import datetime
st.set_page_config(layout="wide")
st.markdown(
"""
<style>
.time {
font-size: 100px !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)
if await asyncio.sleep(1) == None: # <-- prevents printout of "None"
pass
st.experimental_rerun() # <-- rerun here
test = st.empty()
asyncio.run(watch(test))
@asehmi
Copy link
Author

asehmi commented Apr 19, 2022

test_asyncio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment