Keep information despite a app refresh

Hello !
I want to keep the content of my list despite the refresh of the application.

name =  st.text_input("What is your name ?",placeholder="")
surname =  st.text_input("What is your surname ?",placeholder="")
f5_button = st.button('Refresh')
all_the_name = []
if f5_button:
    all_the_name.append(name)
    pyautogui.hotkey('f5')

st.markdown(all_the_name)

If you want the data to persist for a session (not through actually refreshing the page) you can use st.session_state to keep track of the names

import streamlit as st

if "names" not in st.session_state:
    st.session_state["names"] = []

name = st.text_input("What is your name ?", placeholder="")
surname = st.text_input("What is your surname ?", placeholder="")
f5_button = st.button("Refresh")
if f5_button:
    st.session_state["names"].append(f"{name} {surname}")

st.markdown(st.session_state["names"])

However, if you really want it to persist data even if you actually refresh the page, you probably want to store the data either in cookies (through a component like this Cookies support in Streamlit!) of in an external database of some sort (Connect to data sources - Streamlit Docs).

Hope that’s helpful.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.