闪亮的复选框按钮宽度和居中

时间:2019-03-01 09:33:06

标签: r shiny shinydashboard

我用一些按钮创建了一个UI页面,并且checkboxInput按钮有两个问题:

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

更改宽度=“ X%”不会发生任何变化,与'Xpx'相同。 我怀疑这是由于固定的列宽引起的,但是X%的变化对其他按钮也适用。

第二个问题是按钮的外观如下:

enter image description here

我希望它居中而不在左列。

感谢您的帮助,

1 个答案:

答案 0 :(得分:1)

这是使复选框居中的一种方法,但是它需要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

我不知道您希望通过更改宽度看到什么吗?


编辑

要控制复选框输入周围的空白及其垂直对齐方式:

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