{"id":6255,"library":"streamlit-autorefresh","title":"Streamlit Autorefresh","description":"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.","status":"active","version":"1.0.1","language":"en","source_language":"en","source_url":"https://github.com/kmcgrady/streamlit-autorefresh","tags":["streamlit","autorefresh","frontend","utility","dashboard"],"install":[{"cmd":"pip install streamlit-autorefresh","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"streamlit-autorefresh is a custom Streamlit component and requires Streamlit to function.","package":"streamlit","optional":false}],"imports":[{"symbol":"st_autorefresh","correct":"from streamlit_autorefresh import st_autorefresh"}],"quickstart":{"code":"import streamlit as st\nfrom streamlit_autorefresh import st_autorefresh\nimport datetime\n\nst.set_page_config(layout='centered', initial_sidebar_state='auto', page_title='Autorefresh Demo')\n\nst.title(\"Streamlit Autorefresh Demo\")\n\n# Run the autorefresh every 2000 milliseconds (2 seconds) and stop after 100 refreshes\ncount = st_autorefresh(interval=2000, limit=100, key=\"myautocounter\")\n\nif count == 0:\n    st.write(\"Count is zero\")\nelif count % 3 == 0 and count % 5 == 0:\n    st.write(\"FizzBuzz\")\nelif count % 3 == 0:\n    st.write(\"Fizz\")\nelif count % 5 == 0:\n    st.write(\"Buzz\")\nelse:\n    st.write(f\"Current Count: {count}\")\n\nst.write(f\"Last refreshed at: {datetime.datetime.now().strftime('%H:%M:%S')}\")","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"Using a very small `interval` can lead to high CPU utilization on the server, as it constantly pings Streamlit to rerun the script. This can consume significant computing resources.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"If the `key` parameter is not provided or changed, `st_autorefresh` might remount on the Streamlit frontend, leading to a loss of its internal state (like the refresh count).","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"User interactions (e.g., button clicks, widget changes) within the set refresh interval will cause a full Streamlit rerun and effectively reset the `st_autorefresh` timer. This means refreshes might not occur at perfectly fixed intervals from the app's initial load if user interaction is frequent.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"The `streamlit-autorefresh` component works by having the browser ping the server. If the user's browser tab is closed, goes to sleep, or loses its WebSocket connection to the server (e.g., due to network issues or deployment environment timeouts), the auto-refresh mechanism will stop working.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}