How to maintain inputs on changing endpoints

You’ll need to use session_state to park your information while you navigate away from the page. Here’s a short example of committing some information from inputs into a dictionary within session_state.

I also made a little video recently about session_state: Session State Introduction

import streamlit as st

# Initialize on first page load so there is something to look up
if 'page1' not in st.session_state:
    st.session_state.page1 = {'A':'','B':0}

# A function to save information to session_state, bound to a submit button
def submit():
    st.session_state.page1 = {'A':st.session_state.page1A,
                              'B':st.session_state.page1B}

st.button('Submit', on_click=submit)

# Input widgets. Keys allow you to grab their saved info directly. Initial value grabbed from
# your designated save point in session_state allows them to re-render at your saved value
# when navigating back to the page
st.text_input('A', key='page1A', value = st.session_state.page1['A'])
st.number_input('B', key='page1B', value = st.session_state.page1['B'])
1 Like