Introducing multipage apps! 📄

This is something very needed, i have a login page too for a project and i’m dealing with hiding the sidebar, which i’ve done partially. Is there any way the sidebar can be hideable permanently?.
Thanks in advance to everybody!

Hi @MatiasSeb,

Welcome the Streamlit community! :wave: :smiley:

With multipage apps, there’s a hidden configuration option that you can set to true to hide the sidebar navigation.

You can either create a .streamlit/config.toml file containing:

[ui]
hideSidebarNav="true"

or pass it as a command-line flag:

streamlit run app.py --ui.hideSidebarNav=true

Happy Streamlit-ing! :balloon:
Snehan

5 Likes

@snehankekre or anyone please help - Is there a way to hide the sidebar options until a login is successful. I want to organize in pages folder but I want them to be available only when auth is successful.

I just need basic auth and using this link → Authentication without SSO - Streamlit Docs to enable auth.

Just close the sidebar and hide the open button using style until auth then re-run the page to load them.
Use something like this…

import time
import streamlit as st

st.set_page_config(initial_sidebar_state="collapsed")  

if "user_authorised" not in st.session_state:
    st.session_state['user_authorised'] = False

# load cookies for auth status. If exists save to st.session_state['user_authorised']. something like this...
try:
    auth_cookies = .... #load cookies that has saved auth status here. If it exists it will save else the next code bloack will load. 
    st.session_state['user_authorised'] = auth_cookies['status']
except:
    st.session_state['user_authorised'] = False #if it does not exist, it will just go back to its default which is False - suggests new user or perhaps cookies expired.

if st.session_state['user_authorised'] == False:
    st.markdown(
            f"""
                <style>
                    [data-testid="collapsedControl"] {{
                        display: none; 
                    }}
                </style>
                """,
            unsafe_allow_html=True,
        )

   # input auth code here to authorise user.
   user_auth_status = ....

   # Once authorised change session state to True then re-run code
   if user_auth_status == True:
      st.session_state['user_authorised'] = True
      # save status to cookies or database
      ....
      time.sleep(1)
      st.experiemental_rerun()


On rerun, is the code block inside st.session_state[‘user_authorised’] will not be run and user will see sidebar and pages. But make sure you save the user auth status in some database or in cookies and load it at the beginning of the page and save to session_state[‘user_authorised’] because if browser closes session_state will be reset back to False and user will have to re-login again - bad for user experience.

I’m currently implementing a multi-page app using st.navigation and st.page, but I’m encountering issues with deep links or URLs. Specifically, when I try to access a page through a link, only the main page( http://localhost:8501) loads but other pages(http://localhost:8501/page1) will not loads. Do you have any suggestions on how to properly implement deep links in this context?

The deep links function correctly working in a multi-page application built with Streamlit using st.navigation and st.page on mac but encounter issues on Windows.