Hi! I was wondering if it was possible to get the labels I give to my tabs into f-strings. By label, I mean the name of each tab.
Letās say I have two tabs: t1 and t2.
Code snippet:
import streamlit as st
t1, t2 = st.tabs(["tab1", "tab2"])
# This line should give me the label of the tab, where 'x' is the label
t1.write(f"This tab is {x}")
Iāve tried using x = t1.label . However, I got this: <function DeltaGenerator.getattr.<locals>.wrapper at 0x00000206DE79A660>
For example, if the user is viewing a tab named āUser Informationā, I would want to have a line of text that reads āYou are currently viewing: User Informationā. If the user then changes tabs to a second one named āBilling Informationā, that same line of text should then read āYou are currently viewing: Billing Informationā
See the snippet below. Also an additional tip: in some cases it is useful to unpack tabs (and columns) into separate variables (as your snippet does with t1 and t2), in others it is best to keep them as a single tabs iterable.
import streamlit as st
tab_titles = ['tab title 1','tab title 2']
tabs = st.tabs(tabs=tab_titles)
for i,tab in enumerate(tabs):
tab.header(f'You are currently viewing: {tab_titles[i]}')