My code function
genre = st.sidebar.radio( "What\'s your favorite movie genre", ('Comedy', 'Drama', 'Documentary'))
if genre == 'Comedy':
st.write('You selected comedy.')
st.write("You didn\'t select comedy.")
The above code does not wait for the user input. The function returns after displaying the buttons. How can i make it wait for the user input
Streamlit inputs do not wait for user input. The logic flow of a Streamlit app is that your code is going to run top to bottom. Any widgets on the page will render with their default value. They will return that default value immediately and Streamlit keeps going all the way to the end of your page.
Then, when a user selects something, your page is going to rerun from the beginning. It will continue to render and keep going straight through any and all widgets, but now that one that the user just changed will be returning the new value they selected.
you can instead use a selectbox with an empty default value, and then stop if it’s the default value
genre = st.sidebar.selectbox("What's your favorite movie genre",
('', 'Comedy', 'Drama', 'Documentary'))
if genre == '':
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.