Arkadi w
Arkadi w

Reputation: 79

Shiny Checkbox Button Width & Centered

I created a UI page with some buttons and have two problems with the checkboxInput buttons:

  checkboxInput('comissions', label = "Comissions", width = "10%")

Changing the width = "X%" doesn't change anything, same for 'Xpx'. I suspected this is due to fixed column width, but the X% change works for other buttons well.

Second issue is that the button looks like this:

enter image description here

I would like it to be centered and not be in left column.

Thank you for the help,

Upvotes: 3

Views: 1457

Answers (1)

Stéphane Laurent
Stéphane Laurent

Reputation: 84529

Here is a way to center the checkbox, but it requires width = "100%".

library(shiny)

ui <- basicPage(
  fluidRow(
    column(4, 
           sliderInput("costs", "Costs", min = 1, max = 10,  value = 1)),
    column(4, style = "text-align: center;", 
           checkboxInput("comissions", label = "Comissions", width = "100%")),
    column(4, 
           sliderInput("periods", "Number of periods", min = 1, max = 10,  value = 1))
  )
)

server <- function(input, output, session) {}

shinyApp(ui, server)

enter image description here

I don't know what you expect to see by changing the width ?


EDIT

To control the white space around the checkbox input, and its vertical alignment:

library(shiny)

ui <- basicPage(
  fluidRow(
    column(12,
           div(style = "display: inline-block;", 
               sliderInput("costs", "Costs", min = 1, max = 10,  value = 1)
           ),
           div(style = "display: inline-block; margin-left: 20px; margin-right: 20px; vertical-align: -20px;", 
               checkboxInput("comissions", label = "Comissions", width = "100%")
           ),
           div(style = "display: inline-block;", 
               sliderInput("periods", "Number of periods", min = 1, max = 10,  value = 1)
           )
    )
  )
)

server <- function(input, output, session) {}

shinyApp(ui, server)

enter image description here

Upvotes: 5

Related Questions