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!

Yes, definitely this is what I am was looking for!