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)