I am exploring Streamlit to use for one of my projects, and I have a requirement of having sidebar as navigation bars, means these should be selectable and should show only the content falling under it.
Thanks for the reply. Yes its like multipage app, but how can I access same data between multiple pages. For example first page is importing data (Import.py), second page is correlation plot of same data (EDA.py), so same data has to be stored in 2 py files right? How to access same data on both pages if I use multipage app?
@Prashant Yes, what @Goyo suggests is correct. If you import data in one page, one of the best options is to put that data in st.session_state to use it on other pages.
In Multipage_app2.py you have to assign a value to data before calling data.head(). That is how python usually works, you need to define things before you can use them.
ok, but I am importing data in data variable in app2 page already through file uploader,
So my need is to take same data and do some other analysis in other page, lets say multipage app page.
# page 1
import pandas as pd
import streamlit as st
csv = st.file_uploader("Upload a file", type="csv")
if csv is not None:
df = pd.read_csv(csv)
st.session_state["data"] = df
# page 2
import streamlit as st
if "data" in st.session_state:
df = st.session_state["data"]
st.write(df)
# page 3
import streamlit as st
if "data" in st.session_state:
df = st.session_state["data"]
st.write(df)
Thanks a ton Zachary. Yes your code worked for me, however when I go back to home page data disappears. Can you let me know how to save data on home page even if I toggle between multi pages.
@Prashant, it may be the case that the file uploader no longer shows the uploaded file, but it will still be saved in st.session_state. You can access that data on the main page the same way you do on the other pages.
import pandas as pd
import streamlit as st
csv = st.file_uploader("Upload a file", type="csv")
if csv is not None:
df = pd.read_csv(csv)
st.session_state["data"] = df
if "data" in st.session_state:
df = st.session_state["data"]
st.write(df)
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.