How can ı use st.columns with st.tabs (Streamlit)

Viewed 148

I want to work tabs and columns together in streamlit

This is what ım trying to do

with st.tabs("tab1"):
    with st.columns("col1"):
        st.selectbox("City", ["City1", "City2"-])
    with st.columns("col2"):
        st.selectbox("District", ["District1", "District2"])

with st.tabs("tabs2"):
    with st.columns("another_col1"):
         st.selectbox("Another City", ["Another_City1", "Another_City2"])
    with st.columns("another_col2"):
         st.selectbox("Another District", ["Another_District1", "Another_District2"])

When I open each tab separately, I want to see different selectboxes in each. How can I do that ?

2 Answers

You will have to initialize st.columns() in every tab.

tab1, tab2 = st.tabs(["tab1", "tab2"])

with tab1:
    col1, col2 = st.columns(2)
    with col1:
        st.selectbox("City", ["City1", "City2"])
    with col2:
        st.selectbox("District", ["District1", "District2"])

with tab2:
    col1, col2 = st.columns(2)
    with col1:
        st.selectbox("Another City", ["Another_City1", "Another_City2"])
    with col2:
        st.selectbox("Another District", ["Another_District1", "Another_District2"])
tab1, tab2 = st.tabs(["tab1", "tab2"])

with tab1:
    col1, col2 = st.columns(2)
    with col1:
        st.selectbox("City", ["City1", "City2"])
    with col2:
        st.selectbox("District", ["District1", "District2"])

with tab2:
    col1, col2 = st.columns(2)
    with col1:
        st.selectbox("Another City", ["Another_City1", "Another_City2"])
    with col2:
        st.selectbox("Another District", ["Another_District1", "Another_District2"])
Related