How to get selected tab name

Is there any way to get the selected tab of

Hi @imClumsyPanda,

Thanks for posting!

Unfortunately there isnโ€™t a built-in way to do this currently, but this would be a great feature enhancement request โ€“ feel free to submit one here.

Caroline :balloon:

1 Like

There is this TabBar component from GitHub - Mohamed-512/Extra-Streamlit-Components: An all in one place, to find complex or just not available components by default on streamlit. which can be used to update a regular st.container in order to emulate a tab. Itโ€™s not the best documented source code :crying_cat_face: but the TabBar example seems to work fine with version 1.12 :smiley_cat:

A demo:

The code:

import streamlit as st
import extra_streamlit_components as stx

st.code("import extra_streamlit_components as stx")
chosen_id = stx.tab_bar(data=[
    stx.TabBarItemData(id="tab1", title="โœ๏ธ To Do", description="Tasks to take care of"),
    stx.TabBarItemData(id="tab2", title="๐Ÿ“ฃ Done", description="Tasks taken care of"),
    stx.TabBarItemData(id="tab3", title="๐Ÿ’” Overdue", description="Tasks missed out")])

placeholder = st.container()

if chosen_id == "tab1":
    placeholder.markdown(f"## Welcome to `{chosen_id}`")
    placeholder.image("",caption=f"Meowhy from {chosen_id}")

elif chosen_id == "tab2":
    placeholder.markdown(f"## Hello, this is `{chosen_id}`")
    placeholder.image("",caption=f"Hi from {chosen_id}")

elif chosen_id == "tab3":
    placeholder.markdown(f"## And this is ... ๐Ÿฅ ... `{chosen_id}`")
    placeholder.image("",caption=f"Fancy seeing you here at {chosen_id}")

    placeholder = st.empty()

Thank you, Edwin! That helps a lot!