Hide pages using multipage

I would like to know if there is a way to hide some pages using the streamlit multipage. For example, I create a condition to show page1 and page2, in another situation I only show in the side bar page3 and page4…

5 Likes

I don’t think so but I’d really like this feature too.

This can easily be achieved with the old streamlit options menu library (GitHub - victoryhb/streamlit-option-menu). Also powerful when combined with the old multipage module . I honestly don’t like the native integration of multipage.

Let’s pretend you wanna show different menus if a user is logged in or not.

import streamlit as st
from streamlit_option_menu import option_menu

### Import what to render if a user is not logged in:
from public_pages.render_home_page import home

### import stuff to render if a user IS logged in
from privat_pages.display_user_stats import  display_user_stats
from privat_pages.display_user_models import  display_user_models


if  'user_authenticated' not in st.session_state:
    with st.sidebar:
       menu_selection = options_menu["Home","About us","Login"]
       if menu_selection == "Home":
            home()


**if 'user_authenticated' in st.session_state:**
    with st.sidebar:
       menu_selection = options_menu["My stats","My models","Account Settings"]
       if menu_selection == "My stats":
            display_user_stats(user)

       if menu_selection == "My models":
            display_user_models(user)

1 Like

Thanks, but I hope that in the future would have a native solution

This is now possible through st-pages · PyPI

3 Likes

Hi @blackary
Awesome feature and well deserving of the 866 clicks (at last count!)

I would like to use it in my Streamlit app but on your PyPI page it still says it is “An experimental version of Streamlit Multi-Page Apps”.

This makes me a bit nervous to put it into production for my users so would you still consider it to be “experimental” or is it well and truly stable now?

Thanks!

1 Like

@C_Quang I think it will always be somewhat experimental, as it’s using internal APIs from streamlit that really aren’t designed to be for public use. That being said, there is a test suite for the package, and I am using it in “production” for lots of internal apps myself, so I’d say it’s reasonably stable.

I don’t really think it will ever become non-experimental, but we are working on ways to be able to add some of this functionality into native streamlit, so hopefully this package will become unnecessary eventually.

Hi @blackary sorry for the late reply. I will experiment with it thanks.

Also, do you know if it would be possible to incorporate icons from e.g. font awesome as part of the page title in the side bar, rather than an emoji?

I’ve had feedback from my users that the emojis aren’t subtle enough to convey the use/ meaning of the page within the app, and so they lack that intuitive recognition of the page. Also, my users have said the emojis are too informal for my audience (business enterprise users in finance and risk management).

Otherwise it is a great feature.

Hi @C_Quang That has been suggested before, but I haven’t figured out a great way to do it yet. I’d love it if someone wanted to make a PR to st_pages to support fontawesome or some other icon library.

Hi @C_Quang, this is pretty late, but you might be interested in my recent post about how this can now be done natively as of streamlit 1.31.0 New login page navigation example with streamlit 1.31