DT extremely slow (maybe because I can't figure out how to use server side processing?)

1,049 views
Skip to first unread message

Dean Attali

unread,
Jun 3, 2015, 1:23:52 AM6/3/15
to shiny-...@googlegroups.com
I have a dataframe with 50k rows and 4 columns - not that big.  I'm trying to display it using DT.  I used to use the native shiny datatables a few months ago and it was fine, but now with DT it's taking >5 seconds, which is really bad UX.

I'm assuming the whole table is being loaded instead of dynamically loading page by page, and I was hoping maybe using server-side processing would help with that. But I can't figure out how to use serverside processing.

Here is an example app

library(shiny)
df <- data.frame(a = 1:50000, b = 50000:1)
runApp(shinyApp(
  ui = fluidPage(
    DT::dataTableOutput("table")
  ),
  server = function(input, output, session) {
    output$table <- DT::renderDataTable({
      DT::datatable(iris)
    })
  }
))

To combat the slowness, the docs for `datatable` say that I can add a parameter `server = TRUE`. After adding that parameter, I get a message saying I need to specify "ajax" and points me to the website docs https://rstudio.github.io/DT/server.html
But on the website it has a completely different syntax and tells me to use
`DT::renderDataTable(iris, server = FALSE)` without even using the `datatable` function. Running that fails with a message saying that the server param is ignored.

I'm assuming both docs are outdated, which is fine, but I can't figure out how to use the server parameter.

shiny v0.12.0.9002
DT v0.0.41

Joe Cheng

unread,
Jun 3, 2015, 1:28:44 AM6/3/15
to Dean Attali, shiny-...@googlegroups.com
Sorry, this part of the DT package has been in flux the last couple of days precisely because I am unhappy with how confusing it was relative to the old shiny functions. The docs on the website are correct, you need to install the latest DT for it to work though. I'll add a note to the website about that.
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/1d4dbe5d-9cca-4bbc-a6f0-26749a8ebe3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dean Attali

unread,
Jun 3, 2015, 1:29:19 AM6/3/15
to shiny-...@googlegroups.com
Solved: just had to update `DT`. Looks like there have been ~20 version updates in the past 2 weeks, lots of active development! The function doc is correct, website needs to be updated :)

Joe Cheng

unread,
Jun 3, 2015, 1:30:24 AM6/3/15
to Dean Attali, shiny-...@googlegroups.com
Wait, are you sure the website is incorrect? I updated it today.
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.

Dean Attali

unread,
Jun 3, 2015, 1:34:41 AM6/3/15
to shiny-...@googlegroups.com, daat...@gmail.com
I did see all your commits with the long explanations about why you're changing it. Thanks for all that.

And sorry, you're right, the website is indeed correct. I was confused because the syntax is so different from before, but it is correct, you did a good job keeping everything up to date.  And I just noticed that we no longer need to make the awkward call to `DT::datatable()` inside the renderDataTable function, which is great, it really was weird and confusing before. Thanks for the simplification!

Joe Cheng

unread,
Jun 3, 2015, 1:38:27 AM6/3/15
to Dean Attali, shiny-...@googlegroups.com
Cool, glad we are all straightened out.

The old syntax for making it server-side is completely scrapped, yes--hopefully that is a win for everyone. Other than that, the changes we've made are intended to be backward compatible. So you can still do the awkward datatable() call inside renderDataTable if that is how you want to do it (it's weird from a shiny perspective, but it's how most other htmlwidgets work). FWIW I agree with you, I prefer returning the raw data frame myself.

Dean Attali

unread,
Jun 3, 2015, 1:46:12 AM6/3/15
to shiny-...@googlegroups.com, daat...@gmail.com
Hopefully one day the shiny dataTable functions will just import the DT ones so that it'll feel more native instead of using a separate package for an essential output type. I'm not sure if you guys are planning to do that or if it might be too much trouble to deal with the backwards compatibility issues, but that's my selfish hope

Dean Attali

unread,
Jun 3, 2015, 5:37:34 AM6/3/15
to shiny-...@googlegroups.com, daat...@gmail.com
I just came across a "limitation" of using renderDataTable without calling datatable:

If any of the options use a reactive value, they don't get updated when passing the reactive options to renderDataTable.  There might be a way around that that I'm just missing at this time. For example, if I want to use the `colnames` parameter to change all colnames to upper case, then when the dataset changes, the colnames don't change.

Example

runApp(shinyApp(
  ui = fluidPage(
    selectInput("dataset", "Dataset", c("cars", "mtcars")),
    DT::dataTableOutput("table1"),
    DT::dataTableOutput("table2")
  ),
  server = function(input, output, session) {
    data <- reactive({
      get(input$dataset)
    })
    
    output$table1 <- DT::renderDataTable(
      data(), colnames = toupper(colnames(data()))
    )
    
    output$table2 <- DT::renderDataTable(
      DT::datatable(
        data(), colnames = toupper(colnames(data()))
      )
    )    
  }
))


I ended up using a call to datatable in my code because of this, let me know if you think there's a nice workaround without calling datatable

Joe Cheng

unread,
Jun 3, 2015, 3:08:24 PM6/3/15
to Dean Attali, shiny-...@googlegroups.com
That's true. I don't think there's a workaround, and that's a good reason for us to promote the datatable() style.

Reply all
Reply to author
Forward
0 new messages