import streamlit as st
if st.button("String denoting what appears on the button"):
"page_to_switch_to.py") st.switch_page(
34 Custom Page Navigation Buttons
The st.switch_page()
function allows for additional custom navigation within an app.
This can be useful to help guide users through a particular journey, directing their actions more than if you just let them use the sidebar.
st.switch_page
is generally paired with st.button
using the following syntax:
34.0.1 Example App Using st.switch_page
Here is an example app.
Click here to load the app in a new page
In this app, we have a folder structure like so:
We then set up each page as follows:
34.0.2 app.py
This is unchanged from our original multipage app
import streamlit as st
= st.navigation([
pg "home_page.py", title="Welcome!", icon=":material/add_circle:"),
st.Page("des_page.py", title="Run Simulation", icon=":material/laptop:")
st.Page(
])
pg.run()
34.0.3 home_page.py
import streamlit as st
"Clinic Simulation App")
st.title(
"Welcome to the clinic simulation app!")
st.write(
if st.button("Click here to head to the simulation page"):
"des_page.py") st.switch_page(
34.0.4 des_page.py
import streamlit as st
import simpy
import random
import pandas as pd
"Simple One-Step DES")
st.title(
if st.button("Click here to return to the homepage"):
"home_page.py")
st.switch_page(
= st.slider("What is the average length of time between patients arriving?",
patient_iat_slider =1, max_value=30, value=5)
min_value
# Remaining code here...