Hi, I currently have a simple streamlit app. The goal is to take two parameters as input, then generate some text with them.
This is my app right now:
import streamlit as st
input1 = st.number_input('Input 1', min_value=1, max_value=20, value=5)
input2 = st.text_input('Input 2')
if st.button('Generate Some Text'):
text = generate_text(input1, input2)
st.write(text)
This is mostly working great. It takes in the two parameters, and generates text when the button is pressed.
There’s a couple things I would want to change if possible.
Can I make it so the script will only rerun on pressing the button, and not when an input is changed?
Is it possible to remove the ‘Press Enter to Apply’ popup text from text/number inputs?
Welcome to the Streamlit forum. As far as I know, its not possible to make the script run only when the button is pressed, and not on every input change. Making the whole thing run on every input change is integral to how Streamlit works. There is st.stop(), but I don’t believe it does what you’re asking for.
you can associate some inputs to a single form, changes to these inputs won’t trigger rerun except after pressing the submit button → called “Batch modifications”
The solution is @OmarMAmin 's answer. Documentation can be found here.
So, the OP’s code will be like this:
import streamlit as st
form = st.form(key="user_form")
input1 = form.number_input('Input 1', min_value=1, max_value=20, value=5)
input2 = form.text_input('Input 2')
if form .form_submit_button('Generate Some Text'):
text = generate_text(input1, input2)
st.write(text)
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.