building-streamlit-multipage-apps

Build navigable multi-page Streamlit apps with shared session state.

Updated Apr 20, 2025
One-click install
npx skills add https://github.com/cathayrisk/Anya --skill building-streamlit-multipage-apps-cathayrisk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: building-streamlit-multipage-apps
Source: https://github.com/cathayrisk/Anya/tree/main/skills/developing-with-streamlit/skills/building-streamlit-multipage-apps
Command: npx skills add https://github.com/cathayrisk/Anya --skill building-streamlit-multipage-apps-cathayrisk

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides structure and best practices for creating Streamlit applications with multiple pages, avoiding navigation conflicts and ensuring consistent state management across pages.

Core Features & Use Cases

  • Consistent Navigation: Configure top or sidebar navigation with grouped sections or ungrouped pages for clear user flows.
  • Shared and Page-specific State: Initialize global session state in the main module and use prefixed keys for page-specific state to prevent collisions.
  • Conditional Pages & Access Control: Dynamically include or hide pages based on authentication, roles, feature flags, or environment conditions.
  • Imports and Structure Guidance: Use a dedicated app_pages directory and root-level imports to prevent relative import issues.
  • Use Case: Build an analytics dashboard with Home, Analytics, and Settings pages that share an API client and user session data while showing admin pages only to privileged users.

Quick Start

Create a streamlit_app.py that initializes shared session_state, defines navigation using app_pages entries with titles and icons, and calls page.run to render the selected page.

Frequently Asked Questions about building-streamlit-multipage-apps

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a multi-page Streamlit app with sidebar navigation?

To build a multi-page Streamlit app, create an app_pages directory, initialize shared session_state in the main module, define navigation entries with titles and icons, and call page.run to render the selected page. This structure ensures consistent navigation and state management across pages.

How does session state work across multiple pages in Streamlit?

Session state works across multiple Streamlit pages by initializing global state in the main module and using prefixed keys for page-specific state to prevent collisions. This approach allows pages to share data like API clients and user sessions while maintaining isolated page states.

Can I conditionally show or hide pages in a Streamlit app based on user roles?

Yes, you can conditionally include or hide pages in Streamlit based on authentication, roles, feature flags, or environment conditions. This allows you to dynamically show admin pages only to privileged users while maintaining a consistent navigation structure for others.

What is the best way to structure a Streamlit multipage app to avoid import issues?

The best way to structure a Streamlit multipage app is to use a dedicated app_pages directory with root-level imports for page modules. This prevents relative import issues and ensures that shared resources and session state are properly accessible across all pages.

Why does my Streamlit multi-page app lose session state when navigating between pages?

A Streamlit multi-page app loses session state when global state is not initialized in the main module or when page-specific keys collide. Initialize shared session_state centrally and use prefixed keys for page-specific data to maintain consistent state across navigation.

Do I need a specific directory structure for Streamlit apps with grouped navigation sections?

Yes, Streamlit apps with grouped navigation sections require an app_pages directory structure. You define navigation in the main module using app_pages entries with titles and icons, allowing you to configure top or sidebar navigation with grouped sections or ungrouped pages for clear user flows.