How to use serverside processing in DT::datatable?

懵懂的女人 提交于 2019-12-10 14:23:31

问题


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

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

I know that there is a server = TRUE/FALSE option in DT::renderDataTable(), but I don't see any server option in DT::datatable.

How do I use serverside processing using DT::datatable()?


回答1:


The warning message says:

It seems your data is too big for client-side DataTables. You may consider server-side processing: http://rstudio.github.io/DT/server.html

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


来源:https://stackoverflow.com/questions/40664434/how-to-use-serverside-processing-in-dtdatatable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!