putting choice names above the radiobutton in shiny

Viewed 195

I am developing a ui in r shiny. at some point I use radioButtons spread horizontally

radioButtons("my_rb","choose:",1:3,inline=T)

what I get is the radio buttons and their names are in the same line

choose: 1 []  2 []  3 []  

what I really want is:

choose:  1    2    3
         []   []   []

is there a way to achieve that?

1 Answers

Adding some CSS at the top of your UI using tags$head seems to achieve your desired result:

ui <- fluidPage(
    
    tags$head(
        tags$style(HTML("
            .shiny-input-radiogroup label {
                display: inline-block;
                text-align: center;
            }
            .shiny-input-radiogroup label input[type='radio'] {
                display: block;
                margin: 2em auto;
            }

        "))
    ),

    # rest of your UI code

)

This is what it looks like:

enter image description here

Related