Hello guys,
When a user selects “Option 1” and “Option 2” in the selectbox, the resulting selection is not returned as the expected string “Option 2” but instead is returned as a list of characters “[O,p,t,i,o,n, ,2]”. Is there a solution to this issue?
Thank you
options = ["Option 1", "Option 2", "Option 3", "Option 4"]
selected_options = st.multiselect("Select options", options)
if len(selected_options)>1:
second_selected_option = selected_options[1]
st.write("The second selected option is:", second_selected_option)
option_no_2 = st.selectbox('The second selected option is:',second_selected_option)
else:
st.warning("You have not selected at least 2 options.")
What are you expecting with the selectbox after the multiselect?
It reads to me that upon making a second selection, you pass the second selection (which is a string) into the options parameter of selectbox. This parameter expects an iterable, so it will indeed parse the string like a list of characters. If you mean to pass it a list of size one, you need to put your one element into a list, but I don’t understand what you would be doing with the selectbox then.
option_no_2 = st.selectbox('The second selected option is:',[second_selected_option])
Ahh okay mathcatsand, thank you for pointing me about list in selectbox, now i change it from second_selected_option to [second_selected_option] and the result is as expected