如何在DT :: datatable中使用服务器端处理? [英] How to use serverside processing in DT::datatable?
问题描述
我正在使用DT :: datatable()可视化R markdown文件中的表。
I am using DT::datatable() to visualize tables in a R markdown file.
# R markdown file
library(DT)
```{r viewdata}
# this is an example but my actual dataset has 10000 rows and 100 columns
var.df <- data.frame(x = rnorm(1:10000), y = rnorm(1:10000),...)
DT::datatable(data = var.df)
```
运行此代码时,我收到警告,结果HTML加载速度非常慢:
When I run this code, I get a warning and the resulting HTML is very slow to load:
DT::datatable(var.df)
Warning message:
In instance$preRenderHook(instance) :
It seems your data is too big for client-side DataTables. You may consider server-side processing: http://rstudio.github.io/DT/server.html
我知道 DT :: renderDataTable()
中有一个 server = TRUE / FALSE
选项,但是我在 DT :: datatable
中看不到任何服务器选项。
I know that there is a server = TRUE/FALSE
option in DT::renderDataTable()
, but I don't see any server option in DT::datatable
.
如何使用<$使用服务器端处理c $ c> DT :: datatable()?
推荐答案
警告消息说:
看来您的数据对于客户端DataTables来说太大了。您可以考虑服务器端处理: http://rstudio.github.io/DT/server。 html
在文档网站上,它显示了一个闪亮的示例,该示例使用 DT :: renderDataTable()
。要使用服务器端处理模式,首先必须具有服务器。 DT :: datatable()
仅生成一个静态HTML小部件,并且其后没有服务器。所有数据都存在并由您的Web浏览器处理。
On the documentation website, it shows a Shiny example, which uses DT::renderDataTable()
. To use the server-side processing mode, you must have a "server" in the first place. DT::datatable()
only produces a static HTML widget, and there is no server behind it. All data live in and is processed by your web browser.
Shiny不是 DT 的唯一可能服务器,但可能是最方便的服务器(除非您真的了解服务器端处理背后的技术细节)。要将Shiny与R Markdown一起使用,请参阅 R Markdown书籍的第19章。下面是一个示例:
Shiny is not the only possible server for DT, but probably the most convenient one (unless you really understand the technical details behind server-side processing). To use Shiny with R Markdown, see Chapter 19 of the R Markdown book. Here is an example:
---
title: "The server-side processing mode for DT in R Markdown"
runtime: shiny
output: html_document
---
```{r}
DT::renderDT(ggplot2::diamonds)
```
这篇关于如何在DT :: datatable中使用服务器端处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!