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')
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:
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:
double click run_app.py to bring up cmd promp
in cmd prompt I copy the server and paste into firefox/chrome
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
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())
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.