Vishal5
November 11, 2024, 5:17am
1
Hi team,
we are unable to switch between tabs using session.state function.
while clicking a button in frist tab we need to switch to the second tab.
we are running program locally.
we are using streamlit version 1.40.0
the code we are using is st.tabs([‘Testing’,‘Reports’])
5.We need a way to automatically switch from TESTING tab to REPORTS tab by clicking a button in testings tab that gets displayed after a couple of ‘if’ conditions.
naziya
November 11, 2024, 6:54am
2
Hello @Vishal5 can you provide me your code or github link of that project.So that can help you out with the issue your facing.
Goyo
November 11, 2024, 7:39pm
3
You can’t do that with tabs. You can use st.radio , st.segmented_control or st.pills instead.
Now, as a user, I would be surprised by such behavior. But you can do it anyway.
import streamlit as st
def go_to_reports(key):
st.session_state[key] = "Reports"
def handle_choice(key):
choice = st.session_state[key]
if choice == "Testing":
st.button(
"Reports", on_click=go_to_reports, kwargs={"key": key}, key=f"button_{key}"
)
elif choice == "Reports":
st.info("Your report here")
st.header("Using `st.radio`")
st.session_state.setdefault("radio", "Testing")
choice = st.radio(
label="Choice",
options=["Testing", "Reports"],
key="radio",
horizontal=True,
label_visibility="collapsed",
)
handle_choice(key="radio")
st.header("Using `st.segmented_control`")
st.session_state.setdefault("segmented", "Testing")
choice = st.segmented_control(
label="Choice",
options=["Testing", "Reports"],
key="segmented",
label_visibility="collapsed",
)
handle_choice(key="segmented")
st.header("Using `st.pills`")
st.session_state.setdefault("pills", "Testing")
choice = st.pills(
label="Choice",
options=["Testing", "Reports"],
key="pills",
label_visibility="collapsed",
)
handle_choice(key="pills")
system
Closed
May 10, 2025, 7:40pm
4
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.