Update state of St.Expander with a component?

A problem with st.expander is that each time the code reruns it returns to the expanded/closed state determined by the expanded=True/False argument. Apparently this is because the expanded state is handled by the front end and not passed to the back end. Can this be bridged with a component? Can a js component be written that senses the st.expander state and pass it back to Python via Streamlit.setComponentValue()?

Hi @efrank

Streamlit has a session state that you can use to remember the True/False state of the expander widget.

More info on Session State in the Docs page:

And some example code snippets that you can get ideas from:

Thank you, I understand how to use st.session_state, but I don’t know to capture “the True/False state of the expander widget”. I found this post which I understand to mean the True/False state is managed by the front end and is not passable to the back end.

Thanks.