R Shiny中的力箱具有相同的高度

问题描述 投票:0回答:1

我有几个位于流体行中的框,当这些框包含相似数量的信息时,高度对齐没有问题,并且使用较小的浏览器窗口动态调整此高度的效果很好。

当这些框包含的信息量不相同时(例如,两个相邻的表具有不同的行数),就会出现此问题;这导致高度不能整齐地排列。

# NOT RUN {
## Only run this example in interactive R sessions
if (interactive()) {
  library(shiny)

  # A dashboard body with a row of infoBoxes and valueBoxes, and two rows of boxes
  body <- dashboardBody(

    # infoBoxes




    # Boxes
    fluidRow(
      box(status = "primary",
          sliderInput("orders", "Orders", min = 1, max = 2000, value = 650),
          selectInput("progress", "Progress",
                      choices = c("0%" = 0, "20%" = 20, "40%" = 40, "60%" = 60, "80%" = 80,
                                  "100%" = 100)
          )
      ),
      box(title = "Histogram box title",
          status = "warning", solidHeader = TRUE, collapsible = TRUE,
          plotOutput("plot", height = 250)
      )
    )


  )

  server <- function(input, output) {



    output$plot <- renderPlot({
      hist(rnorm(input$orders))
    })
  }

  shinyApp(
    ui = dashboardPage(
      dashboardHeader(),
      dashboardSidebar(),
      body
    ),
    server = server
  )
}
# }

我知道我可以手动设置盒子的高度,但是当我不知道每个盒子中需要显示的信息量时,就会出现问题。我既不想使框太短(并可能切除信息),也不想使框太高(并占用过多的屏幕空间)。但是我确实希望盒子的高度相同。

因此,是否可以提取动态生成的每个框的最大高度并使用该高度将两个框都强制达到该高度?

这对我来说很重要,当这些框包含的信息量不同,并且调整屏幕大小并且[例如]一个框的文本跳到两行,而另一个框则不跳(导致高度不匹配) 。

r shiny box
1个回答
0
投票

您可以在ui中添加一些自定义的CSS。但这会将您的盒子高度设置为固定高度。添加类似的内容:

tags$head(tags$style(type='text/css', '.box{height:400px;}'))
© www.soinside.com 2019 - 2024. All rights reserved.