在 rstudio 查看器中控制数据表输出的高度

Control height of datatableoutput in rstudio viewer

考虑以下降价文档:

---
title: "R Notebook"
output: html_notebook
---

```{r}
library(shiny)

ui <- fluidPage(
    DT::dataTableOutput("tbl")
)
server <- function(input, output, session){
    output$tbl = DT::renderDataTable(
        mtcars,
        server = FALSE,
        selection = list(mode = "multiple", target = "column", selected = c(1)),
        options = list(pageLength = 10, autoWidth = TRUE)
    )
}

runApp(
    appDir = shinyApp(ui, server), 
    launch.browser = rstudioapi::viewer
)
```

如果我 运行 来自 rmarkdown 的闪亮应用程序,table 未完全显示。如果我点击 "open in browser",一切都很好。

问题:

如果我从 rmarkdown 调用应用程序,如何在查看器的整个页面上显示 table?

我认为最简单的方法是将 height 添加到 dataTableOutput。你可以玩弄这个数字,也可以尝试 "rem"、"px" 等。- "em" 最适合我。您可能还想尝试添加 width 参数,以便在您调整 window 大小时 table 缩放,并且可能尝试从 options 中删除 autoWidth,具体取决于最终产品的外观。

---
title: "R Notebook"
output: html_notebook
---

```{r}
library(shiny)

ui <- fluidPage(
    DT::dataTableOutput("tbl", height = "40em")
)
server <- function(input, output, session){
    output$tbl = DT::renderDataTable(
        mtcars,
        server = FALSE,
        selection = list(mode = "multiple", target = "column", selected = c(1)),
        options = list(pageLength = 10, autoWidth = TRUE)
    )
}

runApp(
    appDir = shinyApp(ui, server), 
    launch.browser = rstudioapi::viewer
)
```