import streamlit as st # Initialize session state to track the active tab if 'active_tab' not in st.session_state: st.session_state.active_tab = 0 # Set default tab (0 for first tab) # Create tabs using st.radio or st.selectbox tab_options = ['Tab 1', 'Tab 2', 'Tab 3'] selected_tab = st.radio('Select a tab', tab_options, index=st.session_state.active_tab) # Some condition to trigger the tab change (for example, based on user input or action) def some_condition(): # Define your condition, for example, a button press or other condition return st.button('Switch to Tab 2') # Conditionally switch tabs based on a condition if some_condition(): st.session_state.active_tab = 1 # Switch to Tab 2 (index 1) # Render content based on the selected tab if selected_tab == 'Tab 1': st.write("You are on Tab 1") elif selected_tab == 'Tab 2': st.write("You are on Tab 2") else: st.write("You are on Tab 3")