close the sidebar

I want to close the sidebar, actually there is no way to use css improvement, but after css improvement refresh will see the sidebar, but I do not want to see the sidebar when refreshed

1 Like

I’m not sure I understood your problem. Do you want to always hide the sidebar?

If that is the case, have you tried using the st.set_page_config at the top of your Streamlit app script? Like so:

st.set_page_config(initial_sidebar_state="collapsed")

If you would like to hide the sidebar button too, you could make a CSS adjustment with :

st.markdown(
    """
    <style>
        div[data-testid="collapsedControl"] {
            visibility: hidden;
        }
    </style>
    """,
    unsafe_allow_html=True
)

I hope that helps! Otherwise, please provide more details about your issue…

2 Likes

I am assuming you are using st.markdown. To make changes permanent, best to use javascript via Components API - Streamlit Docs where you add changes to a <style></style>. When app is refreshed, it won’t flash from streamlit format to your new format.

1 Like

Just include the following line of code to hide the sidebar:
st.markdown(“ [data-testid=‘stSidebar’][aria-expanded=‘true’]{displace: none; } ”, unsafe_allow_html=True)

1 Like

The problem has been solved. The official method is to configure it in config.toml. Thank you for your answers.

[client].
ShowSidebarNavigation = false
3 Likes

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