Can i create tabs inside a tab on Streamlit?

:rotating_light: Nested Expanders causing StreamlitAPIException :rotating_light:

Hello Streamlit Community!

I’m developing a local app and facing an issue when trying to use nested expanders. I want to have an outer expander for stage and an inner expander for variable_type. Here’s a snippet of my code:

def render_inputs_for_stage_and_variable_type(stages: Dict[str, Dict[str, List[str]]], selected_data: pd.Series) -> Dict[str, Any]:
    input_values = selected_data.to_dict()

    for stage, variable_types in stages.items():
        with st.expander(stage):  # Stage Tab
            for variable_type, variables in variable_types.items():
                with st.expander(variable_type):  # Variable type Sub-tab
                    for variable in variables:
                        if variable in input_values:
                            input_values[variable] = st.number_input(f"{variable}", value=input_values[variable])

    return input_values

However, when I run the app, I’m greeted with the following error:

StreamlitAPIException: Expanders may not be nested inside other expanders.

I understand from the error that I can’t nest expanders within other expanders. However, I’m keen on achieving a similar functionality. Is there a recommended workaround or an alternative way to represent this nested structure in Streamlit?

Thanks in advance for the assistance!

Hi @Gabriel_Gomes ,

Currently streamlit doesn’t allow expanders inside expanders.

You can check documentation here

If you want other methods you can try this below:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.