Multi-page apps

Is there any support for apps that have multiple pages? My use case is a 3-part workflow that I’d like to separate into three separate views with state carried across them.

Stages generally are: 1- overview of data and category specification, 2- model refinement with active learning, and 3- overview of trained model results).

Is this use case out of scope for streamlit, something that’s possible now, or something that’s planned?

Thanks

4 Likes

Sounds interesting for me as well.

1 Like

Hi. This is in-scope and there are a number of ways to achieve it now.

  1. You can store this part of the state (i.e. which page you’re in) in a selectbox as shown in the Udacity demo.
  2. You can use @tvst’s SessionState hack but please note that this method is undocumented and may not work in the future.
  3. You can store state as a mutable object in the cache using the ignore_hash=True kwarg. (Here’s an example of how to do that.)
  4. You can wait until we have a proper SessionState implementation but that won’t be until the end of November, according to current plans.

Please followup if you have any questions!

7 Likes

Hi @timforr

When you have developed a multipage app please share you ideas, best practices or code. I’m very interested in the subject.

My multipage app is https://github.com/MarcSkovMadsen/awesome-streamlit and https://awesome-streamlit.org/ for inspiration.

3 Likes

Hi guys,

is anyone working on solutions / Feature for multi-page or is there already
some awesome way to do it in Streamlit?

I am waiting for something nice like:

st.nav({
page1: start.py,
page2: home.py
}}

all in the same directory as index.py. Thus displaying the
pages in the header or Sidebar

st.sidenav({
page1: about.py,
page2: settings.py
}}

Looking forward to this feature!

3 Likes

There are ways of doing this based on a modification of the SessionState gist and the rerun() gist. My method uses a stack of state objects to provide the navigation. I built this handling into a “StreamlitPage” base class and subclass all my pages from it. I use a long if … elif … to do the dispatch (as the navigation varies with each page) but the dict method could be made to work as well.

I shared the modified SessionState (it’s attached to one of the Issues on Github). I haven’t shared the base class as: a) it will need rework once Streamlit finalize their approach; b) there are still some glitches which should be fixed when we get to upgrading to the 0.54+ releases and the latest SessionState implementation; and c) there are also several other application services (configuration, logging) built into the class that are specific to our environment and I need to refactor to take those out.

1 Like

HI Marc, your application is really good and the idea of using Selectbox for having displays for multiple displays is inspiring. thanks for sharing.

2 Likes

I’ve build pages into classes and I’ve made a manager than verify choice options with ‘st.ratio’, I’ve created a dictionary and return the options.

look the code:

import streamlit as st
from posting import Posting
from tables import Tables


pages = {'tables':Tables,'posting':Posting}

choice = st.sidebar.radio("Choice your page: ",tuple(pages.keys()))

pages[choice]()
2 Likes

I’ve build the page into the ‘init’ classes

1 Like

Can you provide a link to your classes to see what they do? Do you by any chance expose streamlit methods from your class __init__s?