Page reload and clear all widgets using st.navigation

Hello,

I recently updated my streamlit app to use st.navigation instead of a simple selectbox for a multi-page app.
After the update, my app experienced unexpected page reloads which cleared all already filled widgets by the user.
Reverting solves the problem.

Additional information:
Locally the problem can not be reproduced on my Windows machine. the problem occurred on a deployed app in a ducker on a Linux server.

streamlit==1.38.0
Python 3.8

Thanks

Can you provide a snippet of code that shows the problem? For example create a two-page app with one widget. Show how you do this with the selectbox and how you do this with st.navigation.

I’m confused why it behaves differently on Windows vs Docker. However, it sounds like you are changing from a one-page app (with simulated pages) to a true multipage app. Widgets resetting between pages is expected, but with st.navigation the solution is to put shared widgets in the entrypoint file and not the actual page. If the entrypoint file has the “shared widgets,” they won’t reset.

The current implementation would be something like this:

import streamlit as st

def page1():
    st.write("This is page 1")
    input1 = st.text_input("Input 1")
    if input1:
        input2 = st.text_input("Input 2")
        input3 = st.text_input("Input 3")
        st.write(f"Input 1: {input1}")
        st.write(f"Input 2: {input2}")
        st.write(f"Input 3: {input3}")

def page2():
    st.write("This is page 2")

def main():

    page_names_to_funcs = {
        "Page 1": page1,
        "Page 2": page2
    }

    selected_page = st.sidebar.selectbox("Select a page", page_names_to_funcs.keys())
    
    page_names_to_funcs[selected_page]()
    
if __name__ == '__main__':
    main()

Using the st.vavigation:

import streamlit as st

def page1():
    st.write("This is page 1")
    input1 = st.text_input("Input 1")
    if input1:
        input2 = st.text_input("Input 2")
        input3 = st.text_input("Input 3")
        st.write(f"Input 1: {input1}")
        st.write(f"Input 2: {input2}")
        st.write(f"Input 3: {input3}")

def page2():
    st.write("This is page 2")

def main():

    pg = st.navigation({'first title':
                        [st.Page(page1), st.Page(page2)]})
    pg.run()
    
if __name__ == '__main__':
    main()

In the second implementation while the user is trying to fill inputs 2 and 3, in some cases the page reloads and clears the input provided in input 1 (which leads to inputs 2 and 3 disappearing).
I’m not sure if that is relevant, but it happened on a page full of widgets.

Again, locally I can’t reproduce it.

Please let me know if you need anything else.
Thanks

The widgets shouldn’t behave any differently between the two implementations you’ve given, so I can only guess that a websocket interruption or something is happening in the deployed instance…