Form_submit_button doesn't batch update

Hi all,

I’m new to streamlit and am trying the form_submit_button function.
All I have in the app is a slider and a submit button. When I moved to slider, streamlit automatically prints the number without me pressing the submit button.

My expected result is that it would not print any number until I press submit.

For example, when I moved from the slider from 0 to 65, my expected result is 0. I also expect it to print 65 after I click submit.

Does anyone have any pointers on what I could do to fix this?

Streamlit ver: 0.89.0
python: 3.7.9

import pandas as pd
import streamlit as st

with st.form(key=‘my_form’):

with st.sidebar:
  text_input = st.slider(label='Enter some text')
    submit_button = st.form_submit_button(label='Submit')

st.write(text_input)

Hi @Jwing,

That’s quite strange! I wasn’t able to reproduce the issue on my end with the exact same code. Would you mind sharing a GIF/video of your screen displaying this behavior?

When I tried it on my end, the value of text_input was displayed only when submit_button was clicked:
form-sidebar

Best, :balloon:
Snehan

I tried using the recorder but also got another error (see below picture). Currently using firefox 64 bit ver 92.0.1

I also tried opening in Chrome (version 94.0.4606.61) and see the same error for the recorder. I still see that the number changes without me pressing the submit button too.

Not sure if this helps but I also use another python file called run_app.py to open the server. run_app.py calls my app.py file which contains the slider. The steps I would do is:

  1. double click run_app.py to bring up cmd promp
  2. in cmd prompt I copy the server and paste into firefox/chrome
  3. I adjust the slider to see if it prints the number or not without pressing the button

—run_app.py—

import os
import streamlit.bootstrap
from streamlit import config as _config

dirname = os.path.dirname(file)
filename = os.path.join(dirname, ‘app.py’)

_config.set_option(“server.headless”, True)
args =

streamlit.bootstrap.run(filename, ‘’, args, flag_options={})

—app.py—

import pandas as pd
import streamlit as st

with st.form(key=‘my_form’):
with st.sidebar:
text_input = st.slider(label=‘Enter some text’)
submit_button = st.form_submit_button(label=‘Submit’)

st.write(text_input)

Hi snehankekre,

Appreciate the response. After muddling around stackoverflow and streamlit forums I found the reasoning for the error and a solution. Turns out, streamlit.bootstrap breaks forums (you can see my ‘run_app.py’ script in this thread).

I realized that by running this directly into cmd prompt doesnt break the form compared to executing my run_app.py script. My solution was using this script below to run streamlit. Form works as intended now!

import sys
from streamlit import cli as stcli

if name == ‘main’:
sys.argv = [“streamlit”, “run”, “app.py”]
sys.exit(stcli.main())

Source: https://stackoverflow.com/questions/62760929/how-can-i-run-a-streamlit-app-from-within-a-python-script