From 3a8a4560463885068ec46949f799d934ea117a73 Mon Sep 17 00:00:00 2001 From: MathCatsAnd <98661771+MathCatsAnd@users.noreply.github.com> Date: Sat, 27 May 2023 00:04:10 -0700 Subject: [PATCH 1/2] Noted multipage navigation limitations Added a note to clarify how manual navigation will reset session state. Linked to streamlit-extras for community-supported method to programatically switch pages. Corrected inconsistency between example file names and rendering order displayed in image. --- .../get-started/multipage-apps/index.md | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/content/library/get-started/multipage-apps/index.md b/content/library/get-started/multipage-apps/index.md index a4b89db31..ebae8cf8d 100644 --- a/content/library/get-started/multipage-apps/index.md +++ b/content/library/get-started/multipage-apps/index.md @@ -27,12 +27,13 @@ The "entrypoint file" is the first page the app will show to the user. Once you Once you've created your entrypoint file, you can add pages by creating `.py` files in a `pages/` directory relative to your entrypoint file. For example, if your entrypoint file is `Home.py`, then you can create a `pages/About.py` file to define the "About" page. Here's a valid directory structure for a multipage app: -``` -Home.py # This is the file you run with "streamlit run" +```bash +project/ +└─── Home.py # This is the file you run with "streamlit run" └─── pages/ - └─── About.py # This is a page - └─── 2_Page_two.py # This is another page - └─── 3_😎_three.py # So is this + └─── 1_Page_two.py # This is page + └─── 2_About.py # This is a another page + └─── 3_😎_three.py # So is this ``` @@ -41,7 +42,7 @@ When adding emojis to filenames, it’s best practice to include a numbered-pref -Pages are defined as `.py` files in a `pages/` directory. The filenames of pages are transformed to page names in the sidebar based on the the rules in the [section below](#how-pages-are-labeled-and-sorted-in-the-ui). For example, the `About.py` file will appear as "About" in the sidebar, `2_Page_two.py` appears as "Page two", and `3_😎_three.py` appears as “😎 three”: +Pages are defined as `.py` files in a `pages/` directory. The filenames of pages are transformed to page names in the sidebar based on the the rules in the [section below](#how-pages-are-labeled-and-sorted-in-the-ui). For example, the `2_About.py` file will appear as "About" in the sidebar, `1_Page_two.py` appears as "Page two", and `3_😎_three.py` appears as “😎 three”: ![Directory structure](/images/mpa-add-pages.png) @@ -86,6 +87,7 @@ This table shows examples of filenames and their corresponding labels, sorted by | `123.py` | 123 | | `123_hello_dear_world.py` | hello dear world | | `_12 monkeys.py` | 12 monkeys | +| `about.py` | about | @@ -101,6 +103,16 @@ You can also navigate between pages using URLs. Pages have their own URLs, defin If a user tries to access a URL for a page that does not exist, they will see a modal like the one below, saying the user has requested a page that was not found in the app’s pages/ directory. + + +When navigating between pages by URL, a new browser session will be created and `st.session_state` will be cleared. In +order to retain values in `st.session_state`, a user must use the sidebar navigation links. This means that creating +links to other pages in markdown will result in `st.session_state` resetting. Programatically switching pages while +preserving `st.session_state` is not currently available in Streamlit, but a community-supported option is +[available here](https://extras.streamlit.app/Switch%20page%20function). + + + ## Notes From e83a5ea974c2f73c039800fea3c12087faa02db7 Mon Sep 17 00:00:00 2001 From: MathCatsAnd <98661771+MathCatsAnd@users.noreply.github.com> Date: Sat, 27 May 2023 00:17:46 -0700 Subject: [PATCH 2/2] Swapped paragraph and note Swapped a paragraph and note that were out of order relative to an image. --- content/library/get-started/multipage-apps/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/library/get-started/multipage-apps/index.md b/content/library/get-started/multipage-apps/index.md index ebae8cf8d..5b0fc3d4e 100644 --- a/content/library/get-started/multipage-apps/index.md +++ b/content/library/get-started/multipage-apps/index.md @@ -101,8 +101,6 @@ Pages are automatically shown in a nice navigation UI inside the app's sidebar. You can also navigate between pages using URLs. Pages have their own URLs, defined by the file's `label`. When multiple files have the same `label`, Streamlit picks the first one (based on the ordering [described above](/library/get-started/multipage-apps#how-pages-are-sorted-in-the-sidebar)). Users can view a specific page by visiting the page's URL. -If a user tries to access a URL for a page that does not exist, they will see a modal like the one below, saying the user has requested a page that was not found in the app’s pages/ directory. - When navigating between pages by URL, a new browser session will be created and `st.session_state` will be cleared. In @@ -113,6 +111,8 @@ preserving `st.session_state` is not currently available in Streamlit, but a com +If a user tries to access a URL for a page that does not exist, they will see a modal like the one below, saying the user has requested a page that was not found in the app’s pages/ directory. + ## Notes