【发布时间】:2018-08-14 05:08:17
【问题描述】:
这个问题与 R Shiny 中的所有框类型(框、值框、选项卡框等)有关,但我将举一个使用简单框的示例。
在我的代码中,我经常在同一行中有两个或多个框。当这些框包含相似数量的信息时,高度对齐没有问题,并且使用较小的浏览器窗口动态调整此高度可以正常工作。
当这些框不包含相同数量的信息时(例如,两个相邻且行数不同的表格),就会出现问题;这会导致高度排列不整齐。
我知道我可以手动设置框的高度,但是当我不知道每个框需要显示的信息量时问题就来了。我不想让盒子太短(并可能剪掉信息),也不想让盒子太高(并使用太多的屏幕空间)。但是我确实希望这些盒子的高度相同。
因此,是否可以提取每个框的动态生成的最大高度并使用该高度强制两个框都达到该高度?
当框包含不同数量的信息时,这对我来说很重要)。
类似问题:
R shiny Datatable: control row height to align rows of different tables
Dynamic resizing of ggvis plots in shiny apps
我为下面的 Shiny Example Number 2 提供了修改后的代码:
library(shiny)
# runExample("02_text")
ui <- fluidPage(
# App title ----
titlePanel("Shiny Text"),
# Sidebar layout with a input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Selector for choosing dataset ----
selectInput(inputId = "dataset",
label = "Choose a dataset:",
choices = c("rock", "pressure", "cars")),
# Input: Numeric entry for number of obs to view ----
numericInput(inputId = "obs",
label = "Number of observations to view:",
value = 10)
),
# Main panel for displaying outputs ----
mainPanel(
box(
# Output: Verbatim text for data summary ----
verbatimTextOutput("summary"),
title = "Verbatim",
width = 6
),
# Output: HTML table with requested number of observations ----
box(
tableOutput("view"),
title = "Table",
width = 6
)
)
)
)
server <- function(input, output) {
# Return the requested dataset ----
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
# Generate a summary of the dataset ----
output$summary <- renderPrint({
dataset <- datasetInput()
summary(dataset)
})
# Show the first "n" observations ----
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
}
shinyApp(ui, server)
【问题讨论】:
-
这也是我正在寻求答案的问题。你设法找到答案了吗?我不知道如何使用下面提供的功能。
-
@DmitryIshutin 我相信 css 下面的代码,您可以读取 css 文件以允许格式化闪亮的仪表板。我不得不承认我对此的要求落空了,所以我从未真正使用过它。