【问题标题】:Shiny Checkbox Button Width & Centered闪亮的复选框按钮宽度和居中
【发布时间】:2019-07-23 07:32:19
【问题描述】:

我创建了一个带有一些按钮的 UI 页面,但 checkboxInput 按钮有两个问题:

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

更改宽度 = "X%" 不会改变任何内容,对于 'Xpx' 也是如此。 我怀疑这是由于固定的列宽造成的,但是 X% 的更改对其他按钮也很有效。

第二个问题是按钮看起来像这样:

我希望它居中而不是在左栏中。

感谢您的帮助,

【问题讨论】:

  • 尝试更改父容器元素的宽度和居中规范?相对于父元素居中(这将指定其子元素是居中还是左对齐)
  • 你希望通过改变宽度得到什么?

标签: r shiny shinydashboard


【解决方案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)

我不知道你希望通过改变宽度看到什么?


编辑

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

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)

【讨论】:

  • 这很有帮助。垂直对齐呢?所以它在中间。我想让按钮变小,这样它就不会占用所有这些额外的空白空间。但我相信这受到我的专栏大小的限制?
  • @Arkadiw 要更改垂直位置,您可以在checkboxInput 之前添加div(style = "margin-top : 40px;"),。我会努力摆脱这个空白的,待会见。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-02
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 2018-09-07
  • 1970-01-01
相关资源
最近更新 更多