Behavior of Expanders

-Local App
-Streamlit=1.22.0
-Python=3.8.18

I am trying to understand the behavior of the expanders.

I currently have an expander within the main section of my page (st,expander()) that contains a selectbox

Every time I expand it and then select an item in the box, the page refreshes and the expander collapses again.

However, I also have an expander in the sidebar (st.sidebar.expander()) that contains a selectbox. When i expand that one and select an item in the list the expander does not collapse. This is the behavior I desire, but I’m not sure what is driving that on the main section of the page.

Any ideas what would be causing the difference?

Hi @Phillip_Foster

Typically having a widget nested inside a widget, followed by a widget interaction, would trigger a page refresh and the app reruns again. To prevent this, you’ll have to store the widget values from the widget (the selectbox) in a session state variable.

Please see the following Docs page for example and code snippets:

Hope this helps!

That is not how expanders work by default. There must be something in your code that causes that behavior.

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