question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Radio buttons allowing no selection / "Radio Sets"

See original GitHub issue

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. 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:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
akrolsmircommented, Nov 16, 2020

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!

5reactions
Manish-Hubcommented, Aug 18, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Radio buttons with none selected - UX Stack Exchange
Radio buttons with none selected · 1. Use checkboxes like radio buttons: · 2. Radio buttons with a checkbox "enabler". · 3. Dropdown/pop-up...
Read more >
HTML radio buttons allowing multiple selections
They all need to have the same name attribute. The radio buttons are grouped by the name attribute. Here's an example:
Read more >
Radio Buttons: Always Select One? - Nielsen Norman Group
Excuses for No Default Selection​​ Presumptuous or alienating choice: This is probably the most valid reason for not selecting a radio button by ......
Read more >
<input type="radio"> - HTML: HyperText Markup Language
Only one radio button in a given group can be selected at the same time. Radio buttons are typically rendered as small circles,...
Read more >
Radio buttons without anything selected by default. | OutSystems
Radio buttons without anything selected by default. · 1) Use an integer variable or entity attribute with a default value of zero to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found