diff --git a/streamlit_app.py b/streamlit_app.py index de227b1..40f578a 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -3,6 +3,23 @@ import pandas as pd import streamlit as st + +@st.cache_data +def cache_sleep(i: int, seconds: float = 0.1): + sleep(seconds) + return None + + +# ! Fragments do not trigger a full app rerun, so the fragment will updated after +# ! the entire code is run +# @st.fragment +def render_button(): + with st.echo(): + st.button("Click me") + with st.spinner("Loading data ..."): + sleep(5) + + st.title("Streamlit App Example") st.write( @@ -18,12 +35,11 @@ """ ) -with st.echo(): - st.button("Click me") - with st.spinner("Loading data ..."): - sleep(5) +render_button() + st.write( - "This takes a while to load...simulating a heavy computation or IO process. But it works!" + "This takes a while to load...simulating a heavy computation or IO process. " + "But it works!" ) sleep(2) @@ -55,4 +71,4 @@ for i in range(100): my_bar.progress(i + 1, text=progress_text) - sleep(0.1) + cache_sleep(i)