File size: 1,170 Bytes
365c7d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c11aeae
 
 
 
 
 
 
365c7d0
 
c11aeae
 
365c7d0
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
import streamlit as st

def _progress():
    form_fields = st.session_state['form_fields']
    return sum([bool(x) for x in form_fields.values()]) / len(form_fields)

if 'form_fields' not in st.session_state:
    st.session_state['form_fields'] = {
        'page_1_a': None,
        'page_1_b': None,
        'page_2_a': None,
        'page_2_b': None
    }
    st.session_state['progress'] = _progress

st.sidebar.title("Test Multi-Page App")
st.sidebar.markdown("""With streamlit 1.10.0, you can create [multipage apps](https://docs.streamlit.io/library/get-started/multipage-apps/create-a-multipage-app) right out of the box! πŸŽ‰

This simple demo uses that feature + Streamlit's [session state](https://docs.streamlit.io/library/advanced-features/session-state) to keep track of form fields across multiple pages, and report the global progress of filling out all the forms.

This sort of workflow used to take a lot more effort, so it's cool to see it working a bit smoother now. πŸ€—
""")
st.sidebar.progress(st.session_state['progress']())

"Here's the dict containing all the form field values for the current session:"

st.json(st.session_state['form_fields'])