I’ve a project about some datas and I will use Streamlit for it.
I got the datas from Excel (Node Number Coordinates and Members) and I’ve showed them as you can see at the bottom.
However, I want to plot this datas in second page which is called by “Frame Contacs” but I couldn’t get the dataframes which is located in first page (Nodes)
I 've checked the internet and foun “Session_state” so am I need to use this things or is there any easy way to do it ?
# Check if you've already initialized the data
if 'df' not in st.session_state:
# Get the data if you haven't
df = pd.read_csv('my_file.csv')
# Save the data to session state
st.session_state.df = df
# Retrieve the data from session state
df = st.session_state.df
Session state acts like a dictionary. If you are only loading data based on some user input/action, then you need to tuck that information away in session state before they leave the page e.g. st.session_state['some key'] = df
On another page, you can get that variable back with df = st.session_state['some key']
Just be aware that trying to retrieve something from session state that isn’t there will cause an error, that’s why it’s best practice to check if the key is in session state at the top of page. If it’s not appropriate to force a default value for it on some other page, just make sure to handle the error.
if 'some key' not in st.session_state:
st.warn('Please go back to page 1 and select the data.')
else:
# The rest of your plotting page
pass
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.