-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcustom_page_navigation.qmd
More file actions
88 lines (57 loc) · 1.99 KB
/
custom_page_navigation.qmd
File metadata and controls
88 lines (57 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
title: "Custom Page Navigation Buttons"
filters:
- whitphx/stlite
---
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:
```{python}
#| eval: false
import streamlit as st
if st.button("String denoting what appears on the button"):
st.switch_page("page_to_switch_to.py")
```
### Example App Using st.switch_page
Here is an example app.
```{=html}
<iframe width="780" height="500" src="https://hsma-multipage-custom-navigation-buttons.streamlit.app?embed=true" title="Session State and Callbacks App Example"></iframe>
```
[Click here to load the app in a new page](https://hsma-multipage-custom-navigation-buttons.streamlit.app/)
In this app, we have a folder structure like so:

We then set up each page as follows:
### app.py
*This is unchanged from our original multipage app*
```{python}
#| eval: false
import streamlit as st
pg = st.navigation([
st.Page("home_page.py", title="Welcome!", icon=":material/add_circle:"),
st.Page("des_page.py", title="Run Simulation", icon=":material/laptop:")
])
pg.run()
```
### home_page.py
```{python}
#| eval: false
import streamlit as st
st.title("Clinic Simulation App")
st.write("Welcome to the clinic simulation app!")
if st.button("Click here to head to the simulation page"):
st.switch_page("des_page.py")
```
### des_page.py
```{python}
#| eval: false
import streamlit as st
import simpy
import random
import pandas as pd
st.title("Simple One-Step DES")
if st.button("Click here to return to the homepage"):
st.switch_page("home_page.py")
patient_iat_slider = st.slider("What is the average length of time between patients arriving?",
min_value=1, max_value=30, value=5)
# Remaining code here...
```