From 8b1af4da3e9aabe55034e8219b599e859aab5ada Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Thu, 2 Oct 2025 11:03:19 +0200 Subject: [PATCH 1/2] :art: Show chaching behaviour - do not use fragments - progress bar at the bottom will continue from where it was interupted --- streamlit_app.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index de227b1..23c1cdd 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -3,6 +3,21 @@ 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,10 +33,8 @@ """ ) -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!" ) @@ -55,4 +68,4 @@ for i in range(100): my_bar.progress(i + 1, text=progress_text) - sleep(0.1) + cache_sleep(i) From 59a3e70542288db9d6e442db7800afe9987e1c64 Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Thu, 2 Oct 2025 11:09:37 +0200 Subject: [PATCH 2/2] :art: format --- streamlit_app.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 23c1cdd..40f578a 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -9,7 +9,8 @@ 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 + +# ! Fragments do not trigger a full app rerun, so the fragment will updated after # ! the entire code is run # @st.fragment def render_button(): @@ -18,6 +19,7 @@ def render_button(): with st.spinner("Loading data ..."): sleep(5) + st.title("Streamlit App Example") st.write( @@ -36,7 +38,8 @@ def render_button(): 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)