Having the following code, how can I select the same item several times given in st.multiselect
?
import streamlit as st
options = ["A","B","C"]
st.multiselect("Select the items",options)
I’d appreciate any help!
Having the following code, how can I select the same item several times given in st.multiselect
?
import streamlit as st
options = ["A","B","C"]
st.multiselect("Select the items",options)
I’d appreciate any help!
If you want to just use the multislect widget, then you need to repeat the items within the options list up to the maximum number of times you want to allow its selection. If you want to allow selecting an option up to 10 times, it would need to be included in the options list 10 times.
For example, this allows each option to be selection up to two times.
import streamlit as st
result = st.multiselect('Choose',['A','A','B','B','C','C'])
st.write(result)
If that is not to your liking, you could always use the multiselect to get the unique list of selections and then iterate through the unique selections to create number inputs to get a multiplicity for each. Or you could ditch the multiselect entirely and go straight to getting multiplicity for each of your options (defaulting everything to 0 for not selected).
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
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.
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.
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.
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.