my code run fine
st.markdown(“”“ section[data-testid=“stSidebar”]
[aria-expanded=“true”]
{display: none;}
“””,
unsafe_allow_html=True)
I implemented this code at the beginning of my main.py file, which successfully disabled the sidebar. However, when I attempted to display the sidebar using [display: on;], it did not function as expected. I would appreciate your guidance on the correct method to re-enable the sidebar through a button press, using either display: on or display: yes. Additionally, I seek assistance in managing page visibility based on user permissions. Specifically, I need to restrict access so that not all pages are visible to every user, allowing only those pages for which access has been granted based on user credentials. Please provide the appropriate code to achieve this functionality for hiding and showing pages according to user rights.
The CSS display property doesn’t have an “on” or “yes” value: display - CSS: Cascading Style Sheets | MDN
Alternatively, if you don’t write anything to the sidebar and you hide sidebar navigation, you won’t need to use CSS at all. You can change the visibility of sidebar navigation while an app is running with st.set_option("client.showSidebarNavigation", False)
.
Here is a tutorial in the docs about creating dynamic navigation: Create a dynamic navigation menu - Streamlit Docs
I appreciate your response, boss. However, I have a main.py file and 15 pages located in the pages folder. I would like to display only 3 pages for testing purposes for the user, while providing access to all pages for the admin user. Could you please guide me with the appropriate command and process to resolve this issue, including the complete code?
The tutorial has a complete working example. I recommend using st.navigation
and st.Page
as in the example and not a pages directory if you need to dynamically change which pages are available. In the example, you can see no left navigation before a user logs in. After you select a logged-in role, the correct pages for that role show in navigation.
If you are having trouble implementing the page navigation shown in the turorial, feel free to create a thread with more information about your project and how you tried to implement the linked solution.
I appreciate your swift response, Boss. Could you please provide any sample code that addresses my issue? Your assistance would be immensely helpful, as I am new to Streamlit. Thank you.