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

Dmi*_*tin 5 css dashboard r shiny

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

有办法做到吗?

ism*_*gal 7

Shiny 的列宽基于Bootstrap 12 宽网格系统。您只能指定整数。但是,您可以嵌套多个列以实现细粒度布局。

以下是有关嵌套列的示例:

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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

作为替代方案,您可能需要检查?splitLayout哪个接受 CSS 单元:

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)
Run Code Online (Sandbox Code Playgroud)

结果