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.
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…
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.