3

I found a question that was similar, but didn't address the problem when dealing this Radio Buttons in Shiny in their native form; i.e., without HTML.

I have this line:

column(6, h1(radioButtons(inputId="gender", "Gender", choices = list("combined" = "combined", "male only" = "male", "female only" = "female"), inline=TRUE)))

which looks like this:

enter image description here

I would like to make the labels (e.g., 'combined', 'male only', 'female only') bold.

I tried setting a class, class="radioSelect, as below:

column(6, h1(radioButtons(inputId="gender", "Gender", choices = list(class="radioSelect", combined" = "combined", "male only" = "male", "female only" = "female"), inline=TRUE)))

...but ended up, amusingly and not surprisingly, with this:

enter image description here

Does anyone have any advice on how I can apply a class to a label on a radio button in Shiny this way? Thanks for your attention.

Community
  • 1
  • 1
tumultous_rooster
  • 12,150
  • 32
  • 92
  • 149

3 Answers3

4

I ended up changing the R code to put in a class called radioSelect:

column(6, h1(class="radioSelect", radioButtons(inputId="gender", "Gender", choices = list(...

and then in the CSS file, I accessed the labels with:

.radioSelect label.radio { ...

This worked since the labels all have the class 'radio' on them. Thus I now have control over the labels.

tumultous_rooster
  • 12,150
  • 32
  • 92
  • 149
2

I had a similar issue and found that this worked to change the style of the entire radioButton input:

column(6, h1(radioButtons(inputId="gender", "Gender", choices = list(...)), style = "font-weight:bold;")
Lina
  • 21
  • 2
1
<div class="thisForm">
column(6, h1(radioButtons(inputId="gender", "Gender", choices = list(class="radioSelect", combined" = "combined", "male only" = "male", "female only" = "female"), inline=TRUE)))
</div>

CSS
.thisForm{
font-weight: bold;
}

At least, that's how it appears to be done here in their documentation: http://shiny.rstudio.com/reference/shiny/latest/radioButtons.html

droo46
  • 114
  • 10