Thanks for this amazing application, I have been using streamlit in every project now to visualize and share it with others.
I have a use case, and I am not sure how to solve for it. I want to share my app with multiple people, who can have the option to upload a csv file containing multiple user_ids, and for each session, I want to read in the file and show the user_ids as radio button on the sidebar. The user can select any user_id and see the details for that id (which is fetched from locally saved data/ S3).
The problem is whenever the user selects one of the ids from the side bar, the app refreshes and prompts for file upload again. If i use st.cache, then this caches a certain file for all subsequent sessions. I am not able to figure out how to use SessionState for the same.
I also have the same problem. I would like to keep the file upload saved so that i can use it in my app with multiple pages. Whenever I click on next page and get back again I have to re-upload the file again and all results disappear once I get from a page to an other.
Please if someone has an idea how to use file upload with session-state with multi-page Streamlit app please share the solution with us.
@Ribi@sourav
assign different keys for different users, problem can be solved.
import streamlit as st
userid=st.sidebar.radio("Choose your user ID",("user_id1","user_id2","user_id3","user_id4","user_id5"))
if userid == "user_id1":
upload1=st.file_uploader("Choose your file to upload", key="1")
elif userid == "user_id2":
upload1=st.file_uploader("Choose your file to upload", key="2")
elif userid == "user_id3":
upload1=st.file_uploader("Choose your file to upload", key="3")
elif userid == "user_id4":
upload1=st.file_uploader("Choose your file to upload", key="4")
elif userid == "user_id5":
upload1=st.file_uploader("Choose your file to upload", key="5")
I use my 2 exploers to simulate two different users to do the file upload at the same time when they choose different user id, their upload option is independent, no influence occur between different users.
@BeyondMyself
What I mean is having only one file_uploader in the first page and then when I move to the next page to do some functions which process that file, it does not save the state.
Navigation wise, my uploaded file will disappear once I click on the second tab/ page of my app.
So I would like to have something which saves me the file uploaded and keep it loaded.
And I am also faced with the problem of when I click a button on the same page with my file uploader it also starts from scratch and I have to upload again.
Please let me know if I explained well the situation and thanks a lot for the help
I solved it using this code based on session_state and this way my dataframe is recognised in my other pages ( page 1 : file upload , page 2: data processing on my data )
code:
file = file_upload()
if file:
if 'load_csv' in st.session_state:
df=st.session_state.load_csv
st.write(file.name + " " + "is loaded")
else:
df = load_csv(file)
st.session_state.load_csv = df
Hey, I have a similar problem. I have 6 pages, and I am looking to upload a dataframe in the first page, and it should persist across all remaining pages.
Just confused, should I add this piece of code to every page (every python script), or just the first one?
Hello, maybe I’m a little late, but I want to share the solution I found:
You must simply assign the uploaded file to a session state variable in python, as shown below:
Carga_archivo = st.file_uploader(“ Seleccione el insumo”,type=[“xlsx”,“csv”])
if Carga_archivo is not None:
# Read the uploaded file as a Pandas DataFrame #na_fwl: nombre de archivo fwl
df_insumo = pd.read_excel(Carga_archivo)
# Describe el arvhivo cargado y muestra en formato tabla su contenido
st.session_state[‘df’]=df_insumo
st.session_state[‘name_file’]=Carga_archivo.name
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.