如何在R Shiny中为列设置十进制宽度?

5

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

是否有方法可以实现?

1个回答

7
Shiny的列宽基于Bootstrap 12-wide grid system。您只能指定整数。但是,您可以嵌套多个列以实现细粒度布局。
以下是有关嵌套列的示例:
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)

enter image description here

作为替代方案,您可能希望检查 ?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)

result


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接