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)