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.
pip install streamlit-autorefreshVerified import paths — ran on the pinned version, not inferred.
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.
Use a reasonable `interval` (e.g., several seconds or more) based on your application's actual data update frequency. Monitor server resource usage during development.
Always provide a unique `key` parameter to `st_autorefresh`. If you intend to reset the refresh count, change the `key` to a new unique string.
This is expected behavior due to Streamlit's rerun model. If strict timing is critical, consider making `st_autorefresh` less susceptible to user interaction by adjusting its placement or using Streamlit's session state more carefully for critical timers.
Ensure stable network connectivity for clients. For deployed apps, configure server/proxy timeouts to be sufficiently long to maintain WebSocket connections. This component is not designed for server-side-initiated push updates or unattended refreshes when the client is disconnected.
Install the library using pip: `pip install streamlit-autorefresh`
Add the import statement at the top of your Streamlit application: `from streamlit_autorefresh import st_autorefresh`
Pass an integer value for the 'interval' argument: `st_autorefresh(interval=5000)`
Change the argument name from `interval_secs` to `interval`: `st_autorefresh(interval=3000)`
Pass an integer value for the 'interval' argument: `st_autorefresh(interval=2500)`