我刚刚注意到 DT
库中的 datatable
不会导出基础数据集中的所有行。它仅导出可见行。在以下可重现的示例中,它仅返回默认情况下可见的 25 行。
我想知道是否有解决此问题的方法。
library(shiny)
library(DT)
## Data table output format
data_output <- function(df) {
DT::datatable(df, rownames= FALSE, options = list( dom = 'Bfrtip', buttons = c('excel','pdf','print','colvis'), pageLength = 25, initComplete = DT::JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#369BE9', 'color': '#fff'});",
"}") ),
extensions = c('Buttons','FixedColumns'))
}
## Shiny UI
ui <- basicPage(
h2("The mtcars data"),
DT::dataTableOutput("mytable")
)
## Shiny Server
server <- function(input, output) {
output$mytable = DT::renderDataTable({
data_output(iris)
})
}
shinyApp(ui, server)
最佳答案
## Data table output format
data_output <- function(df) {
DT::datatable(df, rownames= FALSE, options = list( dom = 'Bfrtip', buttons = c('excel','pdf','print','colvis'), pageLength = nrow(df), initComplete = DT::JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#369BE9', 'color': '#fff'});",
"}") ),
extensions = c('Buttons','FixedColumns'))
}
关于r - datatable 不会导出 R Shiny 中数据集中的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50126635/