Skip to content

Commit 0d16bb0

Browse files
Updated Get started > Fundamentals > Additional features to reflect MPAv2 (#1234)
* Udated 'Get Started / Fundamentals / Additional features' to use MPA v2 * Added links to st.Page and st.navigation in additional-features.md * Fix URLs so they don't point to localhost ;) --------- Co-authored-by: Thiago Teixeira <103002884+sfc-gh-tteixeira@users.noreply.github.com>
1 parent 4ad13af commit 0d16bb0

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

content/get-started/fundamentals/additional-features.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,49 @@ your config.toml file, and watch as your app reruns with the new theme colors ap
5050

5151
## Pages
5252

53-
As apps grow large, it becomes useful to organize them into multiple pages. This makes the app easier to manage as a developer and easier to navigate as a user. Streamlit provides a frictionless way to create multipage apps.
53+
As apps grow large, it becomes useful to organize them into multiple pages. This makes the app easier to manage as a developer and easier to navigate as a user. Streamlit provides a powerful way to create multipage apps using [`st.Page`](/develop/api-reference/navigation/st.page) and [`st.navigation`](/develop/api-reference/navigation/st.navigation). Just create your pages and connect them with navigation as follows:
5454

55-
We designed this feature so that building a multipage app is as easy as building a single-page app! Just add more pages to an existing app as follows:
55+
1. Create an entry point script that defines and connects your pages
56+
2. Create separate Python files for each page's content
57+
3. Use [`st.Page`](/develop/api-reference/navigation/st.page) to define your pages and [`st.navigation`](/develop/api-reference/navigation/st.navigation) to connect them
5658

57-
1. In the folder containing your main script, create a new `pages` folder. Let’s say your main script is named `main_page.py`.
58-
2. Add new `.py` files in the `pages` folder to add more pages to your app.
59-
3. Run `streamlit run main_page.py` as usual.
59+
Here's an example of a three-page app:
6060

61-
That’s it! The `main_page.py` script will now correspond to the main page of your app. And you’ll see the other scripts from the `pages` folder in the sidebar page selector. The pages are listed according to filename (without file extensions and disregarding underscores). For example:
61+
<details open>
62+
<summary><code>streamlit_app.py</code></summary>
63+
64+
```python
65+
import streamlit as st
66+
67+
# Define the pages
68+
main_page = st.Page("main_page.py", title="Main Page", icon="🎈")
69+
page_2 = st.Page("page_2.py", title="Page 2", icon="❄️")
70+
page_3 = st.Page("page_3.py", title="Page 3", icon="🎉")
71+
72+
# Set up navigation
73+
pg = st.navigation([main_page, page_2, page_3])
74+
75+
# Run the selected page
76+
pg.run()
77+
```
78+
79+
</details>
6280

6381
<details open>
6482
<summary><code>main_page.py</code></summary>
6583

6684
```python
6785
import streamlit as st
6886

87+
# Main page content
6988
st.markdown("# Main page 🎈")
7089
st.sidebar.markdown("# Main page 🎈")
7190
```
7291

7392
</details>
7493

7594
<details open>
76-
<summary><code>pages/page_2.py</code></summary>
95+
<summary><code>page_2.py</code></summary>
7796

7897
```python
7998
import streamlit as st
@@ -85,7 +104,7 @@ st.sidebar.markdown("# Page 2 ❄️")
85104
</details>
86105

87106
<details open>
88-
<summary><code>pages/page_3.py</code></summary>
107+
<summary><code>page_3.py</code></summary>
89108

90109
```python
91110
import streamlit as st
@@ -97,9 +116,9 @@ st.sidebar.markdown("# Page 3 🎉")
97116
</details>
98117
<br />
99118

100-
Now run `streamlit run main_page.py` and view your shiny new multipage app!
119+
Now run `streamlit run streamlit_app.py` and view your shiny new multipage app! The navigation menu will automatically appear, allowing users to switch between pages.
101120

102-
<Image src="/images/mpa-main-concepts.gif" />
121+
<Image src="/images/mpa-v2-main-concepts.gif" />
103122

104123
Our documentation on [Multipage apps](/develop/concepts/multipage-apps) teaches you how to add pages to your app, including how to define pages, structure and run multipage apps, and navigate between pages. Once you understand the basics, [create your first multipage app](/get-started/tutorials/create-a-multipage-app)!
105124

-994 KB
Binary file not shown.
982 KB
Loading

0 commit comments

Comments
 (0)