Create a variable number of tabs based on dataframe values

In general, tabs have a formulation like the following

    tab1, tab2 = st.tabs(["title1", "title2"])
    with tab1:
    with tab2:

However, what I’d like to do is create a dynamic number of tabs with labels that are based on the unique values for a given dataframe column. Let’s suppose I have a dataframe that looks something like the following:

var value
var1 234
var1 72
var2 9832
var2 972
var3 821
var3 082

What I’d like to do here is create a tab for each unique value of var, which in this case would be 3. So in the end it would behave as though I had coded

tab1, tab2, tab3 = st.tabs(["var1", "var2","var3"])
    with tab1:
    with tab2:
    with tab3:

In other situations, there may be more unique values for var, in which case it would be ncessary to have additjonal tabs.

I’m curious if anyone has solved a similar problem; or if there is some other way to go about this that I am missing.

Is this what you want?

def some_output():
    st.write("The output goes here.")

df = pd.DataFrame(
        "var": ["var1", "var1", "var2", "var2", "var3", "var3"],
        "value": [234, 72, 9832, 972, 821, 82],

tab_labels = df["var"].unique().tolist()
for tab in st.tabs(tab_labels):
    with tab: