Streamlit Autorefresh

1.0.1 · active · verified Tue Apr 14

Streamlit Autorefresh is a Python library that provides a simple way to automatically refresh Streamlit applications. It works by implementing a frontend-based timer that periodically pings the Streamlit server, triggering a rerun of the application script. This component helps in building dashboards or real-time applications that need to display regularly updated information without relying on problematic infinite loops in the backend. The current version is 1.0.1, with releases typically tied to bug fixes or minor enhancements.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `st_autorefresh` to trigger reruns of your Streamlit app at a specified interval (2 seconds) and limit the number of refreshes (100 times). It also shows how to use the returned count to display dynamic content.

import streamlit as st
from streamlit_autorefresh import st_autorefresh
import datetime

st.set_page_config(layout='centered', initial_sidebar_state='auto', page_title='Autorefresh Demo')

st.title("Streamlit Autorefresh Demo")

# Run the autorefresh every 2000 milliseconds (2 seconds) and stop after 100 refreshes
count = st_autorefresh(interval=2000, limit=100, key="myautocounter")

if count == 0:
    st.write("Count is zero")
elif count % 3 == 0 and count % 5 == 0:
    st.write("FizzBuzz")
elif count % 3 == 0:
    st.write("Fizz")
elif count % 5 == 0:
    st.write("Buzz")
else:
    st.write(f"Current Count: {count}")

st.write(f"Last refreshed at: {datetime.datetime.now().strftime('%H:%M:%S')}")

view raw JSON →