dear sir my code executes successfully without errors; however, a problem has emerged where clicking on text transfers it to a function and renders it within an expander, yet this operation causes the page to refresh. i do not wish for this page refresh behavior to occur. Rather, I prefer the data to appear exclusively within the st.expander without initiating a page refresh. Since I have multiple elements distributed across the page and users are actively engaged with the primary interface, a page refresh would terminate all ongoing user activities, necessitating that they re-enter all data to resume their work. My goal is to prevent the page from refreshing. it open to either displaying the data or navigating it to a different page; however, my essential requirement is that the primary page must remain unrefreshed. Please provide a solution and the corresponding code demonstrating how to maintain my primary page data without refreshing, or alternatively, how to store the data in an st.session_state variable, such as st.session_state.textpara, which I can incorporate into my code as required.
import streamlit as st
import streamlit as st
from datetime import datetime
# Get the current date and time
current_time = datetime.now().strftime(“%Y-%m-%d %H:%M:%S”)
# Print it in Streamlit
st.write(f"The current date and time is: **{current_time}**")
if “textpara” not in st.session_state:
st.session_state.textpara = ''
# Check if the specific query parameter was clicked
query_params = st.query_params
if “action” in query_params and query_params[“action”] == “clicked”:
st.session_state.textpara = query_params\["text"\]
st.write(" The text link was clicked!--------",query_params\["text"\])
\# Clear parameters to prevent infinite looping action on refresh
st.query_params.clear()
mfa = “Muhammad”
mfa1 = “1Muhammad”
mfa2 = “2Muhammad”
mfa3 = “3Muhammad”
mfa4 = “4Muhammad”
mfa5 = “5Muhammad”
# Render the clickable text link
st.write(f’{mfa}', unsafe_allow_html=True)
st.write(f’{mfa1}', unsafe_allow_html=True)
st.write(f’{mfa2}', unsafe_allow_html=True)
st.write(f’{mfa3}', unsafe_allow_html=True)
st.write(f’{mfa4}', unsafe_allow_html=True)
st.write(f’{mfa5}', unsafe_allow_html=True)
# Using the ‘with’ notation (recommended)
with st.expander(“See explanation”):
st.write(“Here are the detailed notes or extra info.”)
st.write(st.session_state.textpara)