Ask the community or our support engineers for answers to questions.
import streamlit as st
with st.form("test1"):
genre = st.radio("What's your favorite movie genre",('Comedy', 'Drama', 'Documentary'))
if genre == 'Comedy':
st.write('You selected comedy.')
else:
st.write("You didn't select comedy.")
check_fn=st.form_submit_button("Check_function")
With in form If select the radio buttons the content is not changing . Can you help how to handle this .
What i mean is before clicking on submit button the radio button is not working.
As per radio button want to do some operations .Simillar to like below.
Something like dynamic form as per options.
import streamlit as st
with st.form("test1"):
genre = st.radio("What's your favorite movie genre",('Comedy', 'Drama', 'Documentary'))
dict1=dict()
if genre == 'Comedy':
fun_name=st.text_input("please enter function name")
if len(fun_name.split())>0:
col1,col2 =st.beta_columns([5,2])
dict1=dict()
for i in fun_name.split():
col1.write(i)
dict1[i]=col2.text_input('Enter number of times')
else:
fun_input=st.text_area("Please enter details")
dict1={v.split()[0] : v.split()[1]for v in fun_input.split('\n')}
check_fn=st.form_submit_button("Check_function")
if check_fn:
pass
The issue is that the code below fails when the user doesnât type a comment, so you donât get to the check_fn
dict1={v.split()[0] : v.split()[1]for v in fun_input.split(â\nâ)}
A way to fix this is to change your else to
else:
fun_input=st.text_area(âPlease enter detailsâ)
st.write(âYou didnât select comedy.â)
try:
dict1={v.split()[0] : v.split()[1]for v in fun_input.split(â\nâ)}
except:
pass
That way when the user does not insert a comment the rest of the code still works.
Hello guys I am also having this problem, I need radio buttons in form, and when i clicked submit the data from the radio buttons should be send on st.session.variable. but it does not work. I only get blank string in the session.state
Thanks Goyo, They didnt work even though I used form_submit_button as follows:
col1, col2 = st.columns(2)
with col1:
st.markdown("**Select**")
selected_recommendation = st.radio(
"Please select the most suitable one from the options.",
my_list)
with col2:
st.markdown("**Rating**")
if selected_recommendation is not None:
rating = st.slider(
"Please rate the selected one between 1 and 5.",
1, 5)
st.form_submit_button('Submit',on_click=handle_submit, args=(selected_recommendation,rating,))
I send the arguments with the send button, but default values are sent for both the radio button and the slider. Even if I make changes, the default values are sent instead of new values in the button and slider.
I also tried st.session_state to save selected_recommendation and rating. But again they gave same results.
By the time the callback and its arguments are set, the button has not been clicked and the new values of the widgets are not available, so the old values are passed to the callback.
Assign keys to the widgets and use session_state in the callback instead.
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.