I have a python app that takes multiple inputs from the user and then runs the program. But on Streamlut the app seems to run after each input is added… I want the program to run only after the user has submitted all inputs and hits the “Submit” button.
Also, the program seems to self execute each time the page is reloaded. How do I prevent this?
Yes, it is possible to have the results gated based on clicking a submit button. If I’m not mistaken (I can’t find it as this exact moment), @okld has created an example of this along with using our shared state workaround.
This is a fundamental property of the Streamlit architecture, so it’s not something that can be turned off. In this post, I briefly discuss the design decision for having the refresh model vs. the callback model:
You can set up the app to require the submit button to be clicked before doing computation or loading extra parts of the page by putting it in an if statement that checks if the submit_button variable has state:
with st.form(key='my_form_to_submit'):
...
submit_button = st.form_submit_button(label='Submit')
if submit_button:
...<Code that should only be run after submit button has been clicked>...
This worked for me on streamlit v1.1.0 and Python 3.7.
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.