Run app only after users enters all inputs

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?

Hi @Ajay_Chakravarthy -

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:

Best,
Randy

Hi @Ajay_Chakravarthy,

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.

Best,

Ocean

4 Likes