Instantly collapse or hide sidebar

I have a multipage app where the navigation is accomplished with buttons using the st_pages component. Since I have no need for the sidebar, I want to remove it. But I haven’t been able to do it properly.

I’ve created a minimal example that ilustrates my issue:

Code snippet:

import streamlit as st
from st_pages import Page, show_pages
st.set_page_config('Hello Forum',initial_sidebar_state='collapsed')
        Page('', 'Page 1'),
        Page('', 'Page 2'),
            [data-testid="stSidebar"] {
                display: none

            [data-testid="collapsedControl"] {
                display: none
            """, unsafe_allow_html=True)

(You can reproduce it by copying this code in a “” file and having some other “” file in the same folder)

Expected behavior:

I want one of two things, either:

  1. having the “collapsed” initial_sidebar_state be instant (and not play the closing animation when loading a page)


  1. Instantly hide the sidebar using css

Actual behavior:

As of right now, if I just set the initial state of the sidebar as “collapsed” it shows the sidebar closing each time a page loads, which is very distracting for the user

If I try to hide the sidebar using css (regardless of the initial stat being “collapsed” os “expanded”, the sidebar still displays for a few miliseconds before actually disapearing, which is again very undesirable for user experience.

¿Does anyone know how to approach this differently or how to make my approaches work?

Hey @JesusGarSan,

I see what you mean with the sidebar initially appearing and then disappearing – not a great user experience. Unfortunately, I’m not aware of a way to collapse the sidebar in a multipage app that would avoid this behavior, but I’d recommend opening a feature enhancement request here so the team can consider making this the default behavior for the initial_sidebar_state='collapsed' setting.

1 Like

Thanks for your suggestion, @Caroline. I have oppened a feature enhancement request here.

If anyone who sees this would like this behaviour to be adressed it would be much appreciated if you could engage with the feature enhancement request post!


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