Hey @OOlajide, welcome back to our forum! Itโs been a while
Whenever you want to persist data across sessions, you generally want to use st.session_state. Hereโs an example:
if "toggle_sample_file_value" not in st.session_state:
st.session_state["toggle_sample_file_value"] = True
uploaded_file = st.file_uploader("Choose a file", type=['csv', 'xlsx', 'xls', 'xlsm', 'xlsb'])
if uploaded_file is not None:
st.session_state["toggle_sample_file_value"] = False
sample_file = st.toggle("Toggle to use a sample file", value=st.session_state["toggle_sample_file_value"])
Thanks Arnaud, but Iโd like the toggle to be off by default. So if I toggle on to use a sample file first, then decide to upload a file after, the toggle should switch off after the file upload. I tried the code below but no luck so farโฆ
if "toggle_sample_file_value" not in st.session_state:
st.session_state["toggle_sample_file_value"] = False
uploaded_file = st.file_uploader("Choose a file", type=['csv', 'xlsx', 'xls', 'xlsm', 'xlsb'])
if uploaded_file is not None:
st.session_state["toggle_sample_file_value"] = False
sample_file = st.toggle("Toggle to use a sample file", value=st.session_state["toggle_sample_file_value"])