Basically when pressing “ok” some functions that contain various instructions like querying APIs, extracting JSON data from APIs, table elaboration, formatting and the like are executed to print the seen result. But when you change pages and return the result generated after pressing “ok” is deleted, so you have to enter an ID again and perform another search. Any solution to keep the result from the “My Farm” page when switching to other pages?
st.markdown("### 🔎 Please enter your **farm ID**")
farm_id = st.text_input("#", value="", key="farm_id_input")
if farm_id:
#Call Functions
function_example(farm_id)
Like this? And after that how can I keep the result of the page? If the user enters the first character will the function execute automatically or is there a specific trigger?
Well, I thought the value of the text input would be kept when switching pages, but I was wrong. You need to explicitly store it in the session state, which requires some work:
import streamlit as st
from streamlit import session_state as ss
if "farm_id" not in ss:
ss["farm_id"] = ""
st.markdown("### 🔎 Please enter your **farm ID**")
ss["farm_id"] = st.text_input("#", value=ss["farm_id"])
farm_id = ss["farm_id"] # Just so we can type less from now on.
if farm_id:
#Call Functions
st.write(f"Your farm: {farm_id}")
I still think the button is just clutter and you don’t need it. Try it out.
I try the solution you provided for us and it worked but when I execute pd.read_csv('data.csv) in home page I can’t do it again in other page what is the problem
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.