I have a multi-select input object. I need to gather additional information based upon these selections.
Example 1:
If I Select an item from the multi-select input
Instantiate a Radio Button for an additional option related to the multi-select.
The follow up would be. If I have two items selected in the multi-select, I would need 2 separate radio button (with the same options), but now, I’d need to associate the radio button value with the corresponding multi-select value.
Loop through the list returned by st.multiselect and dynamically create radio buttons within the loop. You could set the radio buttons keys as the name of the iterated multiselect option plus a serial number (to make it unique)
You may need to use session state for the widgets to remember their values post page refresh
In this case I have selected three items on multi-select leading to 3 separate radio buttons and the “view selection radio” shows the selection of each radio button.
Below you will find 2 examples, one with a list and another with a dictionary, at first glance the dictionary example seems to be better as the selection order from the multiselect does not impact the output order. You still can get the same from the list but would take some extra work. Anyway, let me know if that helps.
import streamlit as st
#with list
st.subheader(‘Example 1’)
m1=st.multiselect(‘multiselect’, [‘A’,‘B’,‘C’],key=‘m1’)
list0=[‘A’,‘B’,‘C’]
list1=
for i in m1:
for k in list0:
if k==i: #st.write(‘test’,k,i,v)
test_radio=st.radio(‘group’+k,m1,key=‘testlist’+k)
list1.append('group ‘+k+’ radio choice '+test_radio)
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.