I want to restrict access to certain pages only to selected users (e.g. Admin). How can I implement such a feature? If the user is not a privileged user, then these page tabs should not be visible to him/her.
Thanks for the question! Use st.Page and st.navigation in your entrypoint to include only the pages allowed for the current user’s role. This keeps restricted pages out of the navigation menu. Also check authorization inside each restricted page—hiding a tab alone isn’t access control. Streamlit’s dynamic navigation guide shows role-based page lists, and notes that a page must be included in st.navigation to be routable. The st.Page reference explains that hidden pages can still be reached by URL if registered, so don’t register pages the user isn’t authorized to access.
import streamlit as st
role = st.session_state.get("role")
pages = [st.Page("home.py", title="Home")]
if role == "Admin":
pages.append(st.Page("admin.py", title="Admin"))
page = st.navigation(pages)
page.run()
Ensure role comes from trusted authentication/authorization logic, not a user-editable choice. Sources: