Radio buttons allowing no selection / "Radio Sets"
See original GitHub issueProblem
A use case I have is to present the user a set of models they can access (typically in the sidebar with radio buttons), but to separate the models into groups falling under different categories. Streamlit does not allow you to split radio buttons as follows:
Category 1
- Page 1
- Page 2
Category 2
- Page 3
- Page 4
Although you can make two separate Streamlit radio inputs, you can’t enforce that only one is selected at any one time (both will need to have a selection). The user should be able to select Page 3, and leave Page 1 and Page 2 unselected.
I believe this use case is common to many other users.
Solution
Allowing st.radio() to accept a dictionary as input could be a neat way to achieve this, without affecting the basic radio feature:
dictionary = {'Category 1': ['Page 1, Page 2], 'Category 2': ['Page 3, Page 4]}
selection = st.radio("label", dictionary, index=(1,0))
Selection returns a tuple: (‘Category 1’, ‘Page 3’) or just ‘Page 3’, not sure what is best… Both work for my case.
Alternatively, one could allow the simple radio button feature to have no selection. Then when selecting Page 3, the value in Category 1 could be removed. This is not my preferred approach.
Additional context
I already commented something similar here: https://discuss.streamlit.io/t/radio-button-group-with-no-selection/3229/8?u=kierancondon
Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.
If you’d like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
Thanks for this feature request! It seems like a pretty niche use case, so it’s unlikely we’ll be able to prioritize it at the moment, but we’ll leave this in our backlog to see if other people have the same request. If there’s a lot of community demand (upvotes, comments), we’ll take a second look!
Wow… @akrolsmir I cant see why this being a niche use case… yet it does not get a priority. In several cases of this instance of Radio button option I have seen default selection being null or something that the respective developer chooses to set as per his /her business requirements. In my opinion as well as let me say, this can be my requirement too - I do not wish to see a default selection leading the user to a wrong choice if failed to select the right one in a hurry or by mistake skips the make a choice. ;D Food for thought… I hope my comments adds a reason to prioritize this case. I am loving the Streamlit and I like this feature to be available.