Created
April 19, 2022 18:03
-
-
Save asehmi/19637d813a576ac4fb6cfe6191f7a516 to your computer and use it in GitHub Desktop.
Using asyncio in Streamlit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
Author
asehmi
commented
Apr 19, 2022

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