shinyWidgets icon indicating copy to clipboard operation
shinyWidgets copied to clipboard

`width` attribute has no effect on `radioGroupButtons` and `checkboxGroupButtons`

Open jassler opened this issue 4 years ago • 2 comments

In an effort to get my radioGroupButtons and checkboxGroupButtons aligned to my switchInput, I tried the following:

shiny::shinyApp(
  shiny::fluidPage(
    shinyWidgets::radioGroupButtons('r', choices = c('a', 'b', 'c'), direction = 'vertical', width = '75px'),
    shinyWidgets::checkboxGroupButtons('c', choices = c('d', 'e', 'f'), direction = 'vertical', width = '75px'),
    shinyWidgets::switchInput('s', labelWidth = 50, handleWidth = 25)
  ),
  function(input, output, session) {}
)

My thought was that the widths provided to my switchInput would add up to 75px. However changing the width in my group buttons had no effect in the UI, no matter if I set it to 75px, 100% or some number. Instead I was always given the following output.

Three vertically aligned button groups, the width of the first two does not match the one of the last

Are there certain criterias that have to be met for the parameter to take effect?

jassler avatar Oct 21 '21 17:10 jassler

So from a little bit of debugging inside my browser, it seems as though the buttons don't fill their outside parent. If I append the following line to my shiny UI, it works as I'd expect it to.

tags$script('document.querySelector("#r div").style.width = "100%"')

Or in full:

shiny::shinyApp(
  shiny::fluidPage(
    shinyWidgets::radioGroupButtons('r', choices = c('a', 'b', 'c'), direction = 'vertical', width = '100px'),
    shinyWidgets::checkboxGroupButtons('c', choices = c('d', 'e', 'f'), direction = 'vertical', width = '100px'),
    shinyWidgets::switchInput('s', labelWidth = 50, handleWidth = 25),

    tags$script('document.querySelector("#r div").style.width = "100%"'),
    tags$script('document.querySelector("#c div").style.width = "100%"')
  ),
  function(input, output, session) {}
)

jassler avatar Oct 21 '21 18:10 jassler

You can also do it with CSS for all buttons:

tags$style(".btn-group-vertical {width: 100%;}")

pvictor avatar Oct 25 '21 15:10 pvictor