With this simple code:
with st.sidebar:
st.subheader('Hello ' + self.__user)
The sidebar is properly rendered but after the user collapsed the sidebar, the expand icon seems disabled and the user unable to expand it again.
With this simple code:
with st.sidebar:
st.subheader('Hello ' + self.__user)
The sidebar is properly rendered but after the user collapsed the sidebar, the expand icon seems disabled and the user unable to expand it again.
The state of the sidebar is controlled by the user. The only thing that you can control through page configuration is the initial state of the sidebar. This is true for both sidebar and expander.
If you need to force the state of the sidebar, youâll have to rerun the app a couple times, toggling the initial first to the opposite of what you want, before returning it to what you actually want. This forces Streamlit to recognize âsomething differentâ and and discard the userâs chosen state.
import streamlit as st
SIDEBAR_STATE = {True: "expanded", False: "collapsed"}
if "open" not in st.session_state:
st.session_state.open = True
st.session_state.rerun = False
def open():
st.session_state.open = True
st.session_state.rerun = True
def close():
st.session_state.open = False
st.session_state.rerun = True
if st.session_state.rerun:
st.set_page_config(initial_sidebar_state=SIDEBAR_STATE[not st.session_state.open])
st.session_state.rerun = False
st.rerun()
st.set_page_config(initial_sidebar_state=SIDEBAR_STATE[st.session_state.open])
st.sidebar.write("foo")
st.button("Open", on_click=open)
st.button("Close", on_click=close)
st.button("Rerun")
Thanks @mathcatsand . The problem I have is that the user itself is unable to control the state of the sidebar. After the user collapsed the sidebar, the user is unable to expand it.
The simple code you posted cannot cause that, the problem lies somewhere in the rest of the code.
Thanks Goyo. I retraced all the styles I implemented and found out a conflict. You can replicate it by having this style:
styles = {
ânavâ: {
âbackground-colorâ: âwhiteâ,
âdisplayâ: âflexâ,
},
}
options = {
âshow_menuâ: False
}
pages = [ââ]
page = st_navbar(
pages,
styles=styles,
options=options
)
It is now behaving as expected after removing these lines.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.