How to put shiny radioGroupButtons into columns

512 views Asked by At

I'd like to align some radioGroupButtons() from shinyWidgets into 5 equally spaced columns. I'd also like the buttons to all have the same width. The column widths work a little better if I use direction = "vertical" but the columns end up even further away from each other. Here's what it looks like as-is.

enter image description here

Maybe the answer is hidden here but I couldn't figure it out.

library(shiny)
library(shinyWidgets)

my_css <-
  ".btn-group, .btn-group-vertical {
    column-count: 5;
  }"


ui <- 
  fluidPage(
    tags$head(tags$style(HTML(my_css))),
    radioGroupButtons(
      inputId = "somevalue1",
      label = NULL,
      choices = 
        setNames(
          1:20,
          rep(c("xs", "medium", "very long", "a whole lotta text"), 5)
        )#, direction = "vertical"
    )
  )


server <- function(input, output) {}

shinyApp(ui, server)
1

There are 1 answers

0
gdevaux On BEST ANSWER

You can have everything with the same width by playing with the CSS of the classe btn-group-toggle and radiobtn.

my_css <-
  ".btn-group, .btn-group-vertical {
    column-count: 5;
  }
  
  .btn-group-toggle {
  width:200px;
  }

  .radiobtn { 
    width:200px;
  }"