Toggle Sidebar

Sort of. Just like st.expander your Streamlit server only knows the initial state of the sidebar. The opening or closing of the sidebar for the GUI is only known to the frontend. In order to forcibly rerender the sidebar, you have to change the initial state so Streamlit considers it to be “different.” That means you may need a little trick to render the sidebar the opposite of how you want, then quickly rerun the app to force it into the desired state.

Here’s a thread discussing the cycling through states needed for st.expander: Closing current expander and opening next by button-press - #10 by mathcatsand