Problem
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. In the example below, the user should be able to select Page 3, and leave Page 1 and Page 2 unselected. This is common navigation in documentation or blogs.
Category 1
- Page 1
- Page 2
Category 2
- Page 3
- Page 4
Although you can make two separate Streamlit radio inputs now, you can’t enforce that only one is selected at any one time (both will need to have a selection).
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 posted this feature proposal to GitHub