Hide/Close the Sidebar Programmatically

Hello there!

Are there any ways to close the streamlit sidebar programmatically?

The goal is to have the sidebar opened at the beginning as it is where the user can select some of the modules.
But then I would like to automatically “fold/close” the sidebar so that the user can have a “full screen” experience on.

Above is my demo app sidebar divided into different “pages” and including a SessionState module so when the user connects to the application, they first access a streamlit form to authenticate to the App on my backend database:
Once they are logged in properly they will automatically land on the Welcome page and the sidebar will be expanded by default.

Next, if the user selects for example “Market Overview” module, I would like to automatically hide/close the sidebar at this stage. So the user doesn’t have to manually close it and can have a full-screen experience on the module.

Hope it is clear let me know what you think! :upside_down_face:

Hi, how to achieve the logout function?

Since July 1st Streamlit now implement SessionState Session State for Streamlit 🎈
So you could basically store your username and password or is_valid state in SessionState object embedded in Streamlit, I will try to write a code snippet for you when I have the time.

thanks for your kindly support