Nested Expanders causing StreamlitAPIException
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!