Hide restricted page in navbar in multipage app

Summary

Hey there, I work with a multipage app. I’m now trying to hide a page for specific users by using st.experimental_user.email. On the main Page I’m able to not display the restricted page if a users does not have access. However, the restricted page keeps being displayed in the navbar. How can I also hide the page in the navbar?

Steps to reproduce

streamlit_app.py:

import streamlit as st
from restrictions import RESTRICTED_USERS

if st.experimental_user.email not in RESTRICTED_USERS:
    st.markdown("- [First Page](/first_page)")
st.markdown("- [Second Page](/second_page)")

restrictions.py:

RESTRICTED_USERS = { 'user@sample.com'}

1_first_page.py:

import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import streamlit as st
from restrictions import RESTRICTED_USERS

# ----- Restriction ----
if st.experimental_user.email not in RESTRICTED_USERS:
    pass
else:
    st.warning('You do not have access to this page.', icon='🔑')
    st.stop()

st.text('This should only be displayed if the user does not belong to the restricted users.')

File Structure:

streamlit_app.py
restrictions.py
└─── pages/
  └─── 1_first_page.py (to be restricted)
  └─── 2_second_page.py

As far as I know, this is not possible a the moment. This issue is probably the closest to what you need, though maybe the specific ‘conditional pages’ feature deserves its own request.

If you absolutely need to do this, and you do not have many pages, it could be done by emulating pages in the pre-multipage apps way. That is, by putting a radio or select box in the sidebar and using that as a homemade ‘page selector’, adjusting options as needed.

1 Like

This is now possible through st-pages · PyPI

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