How to use serverside processing in DT::datatable?
Asked Answered
A

2

9

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

Alainaalaine answered 17/11, 2016 at 20:30 Comment(4)
there is actually no server with markdown: the HTML is generated once. Shiny has a server this is why you can render on server with DT::renderDataTable()Waaf
Got it. Thanks! Can you move your comment to an answer so I can accept it?Alainaalaine
Markdown has the option to be run as a shiny app link. Looking at the datatable() documentation any option from the underlying javascript library can be used, including serverSide link. Yet this is not working.....Spadix
Ah, wrapping my call to datatable() inside renderDataTable({}) was all that was required to make this work.Spadix
C
6

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)
```
Cigarillo answered 11/7, 2019 at 14:51 Comment(0)
V
-1

This function will start a shiny server and show the datatable.

Call it with an object returned by DT::datatable:

dtss <- function(dt) {
  ui <- shiny::fluidPage(
    shiny::titlePanel("Edgar Anderson's Iris Data"),
    DT::dataTableOutput("dt")
  )

  server <- function(input, output) {
    output$dt <- DT::renderDT({
      dt
    })
  }

  shiny::shinyApp(ui = ui, server = server)
}
Vesuvian answered 15/1, 2024 at 23:20 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.