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.