出典1:ページ切替
出典2:ページ間データ保持
出典3:画面リフレッシュ(リロード)
streamlit_autorefresh
■Parameters interval: int Amount of time in milliseconds to limit: int or None Amount of refreshes to allow. If none, it will refresh infinitely. While infinite refreshes sounds nice, it will continue to utilize computing resources. debounce: boolean Whether to delay the autorefresh when user interaction occurs. Defaults to True in order to avoid refreshes interfering with interaction effects on scripts. key: str or None An optional key that uniquely identifies this component. If this is None, and the component's arguments are changed, the component will be re-mounted in the Streamlit frontend and lose its current state.
■インストール pip install streamlit-autorefresh ■サンプルコード import streamlit as st from streamlit_autorefresh import st_autorefresh # Run the autorefresh about every 2000 milliseconds (2 seconds) and stop # after it's been refreshed 100 times. count = st_autorefresh(interval=2000, limit=100, key="fizzbuzzcounter") # The function returns a counter for number of refreshes. This allows the # ability to make special requests at different intervals based on the count 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"Count: {count}")
■考察 count = st_autorefresh(interval=10, limit=1) とすればワンショットの画面更新になるが、フォームのなかの入力値がクリアされない。
フォームの中のクリアはこちら↓