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