通过 RMarkdown-Shiny 从 DT 按钮下载不完整的 CSV/Excel 行

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

我有以下 RMarkdown Shiny 文档:

---
title: "Title"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    vertical_layout: scroll
    theme:  bootstrap
    orientation: rows
---

```{r setup, include=FALSE}
library(flexdashboard)
```



Rows {data-height=400}
-----------------------------------------------------------------------

### Table

``` {r show_table}
library(DT)
library(ggplot2)
renderDataTable( {
  dat  <- diamonds
   },
   extensions = c('Scroller','Buttons'),
    class = 'compact cell-border stripe',  rownames = FALSE,
    filter = list( position = 'top', clear = FALSE, plain =TRUE ),
    options = list(
        deferRender = FALSE,
        scrollY = 200,
        scroller = TRUE,
        dom = 'Bfrtip',
        buttons = c('csv', 'excel')
      )
  )
```

产生此文件:

enter image description here

我下载Excel文件后,行数只有~90行 未完成 53,940 个条目。这是为什么?我该如何解决?

r shiny r-markdown dt
1个回答
2
投票

默认情况下

DT
使用服务器端处理,因此仅将可见数据发送到浏览器。这就是为什么 Excel 文件仅包含可见数据(如果删除
scrollY = 200
scroller = TRUE
,这将变得非常清晰)。

要下载所有数据,您需要通过包含

server = FALSE
来禁用服务器端处理,例如

class = 'compact cell-border stripe',  rownames = FALSE,
server = FALSE,
filter = list( position = 'top', clear = FALSE, plain =TRUE ),

不幸的是,这使得加载和浏览表格变得非常慢(至少在我的计算机上)。

顺便说一句:您的代码取决于

diamonds
数据集,它是
ggplot2
的一部分。

© www.soinside.com 2019 - 2025. All rights reserved.