liveBook · Manning

St.navigation

As explained in Build Python Web Apps with Streamlit

st.navigation is a Streamlit API function that creates navigation from page definitions and returns the page selected for execution.

Use st.navigation to turn several Streamlit pages into a selectable app flow. Give it a list of st.Page objects; it displays the navigation options and returns the page the user selected. section 8.4.1

The basic workflow is:

  • Define pages with st.Page, including each page's file, title, and optional icon. section 8.4.1
  • Pass the available pages to st.navigation as a list. section 8.4.1
  • Call .run() on the returned Page so Streamlit loads the selected page. section 8.4.1

Show different pages after login

Store login state in st.session_state, then choose the navigation list conditionally: logged-in users receive Home and Log out, while other users receive Log in and Sign up. After login, set the user state and call st.rerun(); the logout page clears the state and reruns the app. section 8.4.3

Listing 8.8 main.py, revised yet again
import streamlit as st
from backend.hub import Hub

pages = {
  "login": st.Page("frontend/login.py", title="Log in",
                   icon=":material/login:"),
  "signup": st.Page("frontend/signup.py", title="Sign up", 
                    icon=":material/person_add:"),
}

if 'hub' not in st.session_state:
  st.session_state.hub = Hub()

page = st.navigation([pages['login'], pages['signup']])
page.run()

A complete minimal main.py example shows page definitions, shared session state, navigation creation, and page execution together. section 8.4.1

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines page lists, selection, execution, and conditional options, but does not examine framework internals.
Examples
Uses login, signup, home, and logout pages with icons, shared state, and authentication-dependent navigation.
What it assumes
Assumes basic Streamlit widgets and Python files while demonstrating page definitions and shared session state.
What you can do after
Configure a Streamlit multi-page app, select pages dynamically, and run the page returned by navigation.
How it connects
Connects st.Page, st.session_state, st.page_link, and rerun-based authentication flows.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.