如何设置R闪亮中的列的小数宽度?

2022-08-21 00:00:00 r dashboard shiny css

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

有办法吗?


解决方案

SHINY的列宽基于Bootstrap 12-wide grid system。您只能指定整数。但是,您可以nest multiple columns实现细粒度布局。

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

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)

作为替代方案,您可能需要选中?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)

相关文章