如何为 R Shiny 中的列设置小数宽度?

How can I set decimal width for a column in R Shiny?

我想在我的 R Shiny 仪表板中为 column() 元素设置小数宽度。例如,我需要 5 列,因此我需要每列 2.4 的宽度。

有办法吗?

Shiny 的列宽基于 Bootstrap 12-wide grid system. You can only specify integers. However, you can 以实现细粒度布局。

这是一个关于嵌套列的示例:

library(shiny)

ui <- fluidPage(fluidRow(
  p(),
  column(4, p(), style = "background-color: red;"),
  column(4, p(), style = "background-color: green;"),
  column(
    4,
    column(4, p(), style = "background-color: red;"),
    column(7, p(), style = "background-color: green;"),
    column(1, p(), style = "background-color: blue;")
  ),
))

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

shinyApp(ui, server)

作为替代方案,您可能需要检查接受 CSS 单位的 ?splitLayout

library(shiny)

ui <- fluidPage(splitLayout(
  p("red", style = "background-color: red;"),
  p("green", style = "background-color: green;"),
  p("blue", style = "background-color: blue;"),
  p("yellow", style = "background-color: yellow;"),
  p("orange", style = "background-color: orange;"),
  cellWidths = "20%"
))

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

shinyApp(ui, server)