How to put shiny radioGroupButtons into columns

三世轮回 提交于 2021-01-28 07:12:50

问题


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.

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:


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;
  }"


来源:https://stackoverflow.com/questions/65056764/how-to-put-shiny-radiogroupbuttons-into-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!