Create multipages app by code

Currently, if we want to create a multipages app, we have to put pages into pages folder and give them name like 1_pageapple.py, and pageapple will show as label on web page.

This will make three problem:

  1. It is hard to arrange pages. if I already have 10 pages and I want to insert a new page in index 2, I have to rename 8 files.
  2. The web project structure is too rigid, we can not put some util modules in pages directory or put different pages in any where we like.
  3. filename is not clean. Actually, label on web page is not the style of my filenames, I do not like emoji in my filenames.

I think streamlit at least should provide a manually model, just like:


st.config(auto_pages=False)

st.add_pages(
  {
  "🌲label1_name%test": "page1_file_path.py",
  "📚label2_name": "folder/page1_file_path.py",
  }
)

8 Likes

I agree that, although it simplifies building multi-pages apps compared to a full manual set up with radio buttons or the like and a switching logic (I actually refactored my code from the latter to the new pages structure when updating Streamlit to the latest version), it lacks some flexibility that would make it more attractive:

  • Be able to insert components above or below the menu in the side bar (make the pages menu a component?)
  • Be able to organize and reorganize pages at will with minimum effort like you suggested, with a dictionary structure for example
  • Be able to use any image as an icon instead of emojis in file names only (which make those files complicated to refer to as you need to copy/paste emojis, and also emojis do not make the best icons…)
2 Likes