简体   繁体   中英

Control height of datatableoutput in rstudio viewer

Consider the following markdown document:

---
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
)
```

If i run the shiny app from rmarkdown, the table is not fully shown. If i click on "open in browser", everything is rendered fine.

Question:

How can i Show the table on the full page within the Viewer if i invoke the app from rmarkdown?

在此处输入图片说明

I think the simplest method would be to add height to dataTableOutput . You can play around with the number, and also try "rem", "px", etc. – "em" worked best for me. You might also want to try adding the width argument so the table scales when you resize the window, and perhaps try removing autoWidth from options , depending on how the final product looks.

---
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
)
```

数据表截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM