Need to Switch internally from Tab1 to Tab2 on clicking a button in Tab1

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.

  1. we are running program locally.
  2. we are using streamlit version 1.40.0
  3. 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.

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.

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")