Hi, I have an app which accepts file upload. When I upload, it calls a read function. Then from the file, I show some options as multiselect, when I submit the multiselect option, the read function calls again. I tried caching or session state but it is not working. Can someone help?
Steps to reproduce
with tempfile.NamedTemporaryFile(mode="wb") as temp:
with st.spinner('This may take a while. Wait for it...'):
bytes_data = file.getvalue()
df = MyFunctionReadsFromPathAndAggregations(temp.name)
session_state = st.session_state
if "df" not in session_state:
file = st.file_uploader("Upload file.")
if file is not None:
df = read_file(file)
selected_authors = st.multiselect(
"Choose authors of the group",
submit_button = st.form_submit_button(label='Submit')
# do the things
I expect to run my function inside read_file once. After reading, I show some keys from dataframe as multiselect, then user selects the scope and submits. Now it should not read dataframe again.
After clicking submit, it recalls read_file again.