Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use serverside processing in DT::datatable?

Tags:

r

r-markdown

dt

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()?

like image 380
Komal Rathi Avatar asked Nov 17 '16 20:11

Komal Rathi


People also ask

How to make server-side DataTables?

Server-side processing in DataTables is enabled through use of the serverSide option. Simply set it to true and DataTables will operate in server-side processing mode. You will also want to use the ajax option to specify the URL where DataTables should get its Ajax data from.

What is processing in Datatable?

Description. This event is fired when DataTables is doing some kind of processing - be it, sorting, filtering or any other kind of data processing. It can be used to indicate to the end user that there is something happening, or that something has finished.

How does server-side Datatable work?

With a large amount of data on the client-side, the browser can start to slow down, so DataTables has a server-side processing mode which hands off all of the "hard work" to the server. This allows DataTables to display data from results sets which may be many millions of records in size.

What is the difference between server-side and client side Datatable?

Description. DataTables has two fundamental modes of operation: Client-side processing - where filtering, paging and sorting calculations are all performed in the web-browser. Server-side processing - where filtering, paging and sorting calculations are all performed by a server.


1 Answers

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)
```
like image 133
Yihui Xie Avatar answered Nov 05 '22 01:11

Yihui Xie