DT Server side processing with Filters is very slow

775 views
Skip to first unread message

Massimiliano Moro

unread,
Mar 27, 2015, 1:17:23 PM3/27/15
to shiny-...@googlegroups.com
I noticed when I use the server side process and the filter='top' with DT, the rendering is very slow. I think because DT is calculating the drop-downs for the filters.
With the standard shiny renderTable this is not happening and it is very fast. (no drop down on filters?)

How can I use the classic filters w/out drop-downs with DT? I need a fast server-side datatable where users can filter the list.

Thanks
Max

Yihui Xie

unread,
Mar 27, 2015, 1:33:29 PM3/27/15
to Massimiliano Moro, shiny-discuss
What is the size of your data? And what are the types of the columns?
(numeric, character, factor, ...) Are you sure you were using
server-side processing? i.e. datatable(server = TRUE) The
implementation of server-side processing in DT is pretty much the same
as shiny, so I cannot imagine what could make DT significantly slower
than shiny, except when you have a factor column with a huge number of
categories (thanks to the evil stringsAsFactor option...), in which
case I think it makes more sense to coerce that column to character.

Regards,
Yihui

Massimiliano Moro

unread,
Mar 27, 2015, 1:55:29 PM3/27/15
to shiny-...@googlegroups.com
Thank you very much for quick reply.
I've 30,000 rows with 40 cols, I'm using the server side options and ajax component.
I'll try to create a portable example so we can have some code to look at.
Thanks
Max

Yihui Xie

unread,
Mar 27, 2015, 2:01:53 PM3/27/15
to Massimiliano Moro, shiny-discuss
That will be much appreciated. You can just simulate some random data.

Regards,
Yihui

Massimiliano Moro

unread,
Mar 27, 2015, 3:32:05 PM3/27/15
to shiny-...@googlegroups.com, massimil...@gmail.com
OK, with random data it works fine, I think I've some issue with my data, I'll investigate.

Meantime, I've a new question about DT, I hope I can use this thread.

I receive an AJAX error when I filter for something that is not in the table.
Here how to replicate the error
CODE:
----
library(shiny)
library(data.table)

data=data.table(mtcars)
data$model =factor(rownames(mtcars))
data$cyl=factor(as.character(data$cyl))

shinyApp(
    ui = fluidPage(
        title = 'Server-side processing of DataTables',
        fluidRow(
            DT::dataTableOutput('tbl')
        )
    ),
    server = function(input, output, session) {
        
        output$tbl = DT::renderDataTable(
            datatable(data
                      , server = TRUE
                      , filter='top'
                      , list(ajax = list(url = dataTableAjax(session, data)))
                      )
            )
    }
)
----
Here how to replicate the erorr
1) PASTE and RUN the code from the console
2) FILTER the MODEL (most right cell) = Mazda RX4
3) FILTER the CY= 8

the error should show up has 

I hope is clear.

I really like DT and I'm going to implement on my apps, great job!

Thanks

Max

Yihui Xie

unread,
Mar 27, 2015, 4:30:36 PM3/27/15
to Massimiliano Moro, shiny-discuss
Thanks for the example for the Ajax error. I think it is a JSON
conversion problem. We are currently working on switching from
jsonlite to RJSONIO in shiny and htmlwidgets. I do not see the error
(see the attached screenshot), but that is probably because I'm using
the development version of shiny. If you do not mind, please test
this:

update.packages(ask = FALSE) # or only update jsonlite
devtools::install_github(c('rstudio/shiny', 'rstudio/DT'))

Regards,
Yihui
DT.png

Massimiliano Moro

unread,
Mar 27, 2015, 4:52:12 PM3/27/15
to shiny-...@googlegroups.com, massimil...@gmail.com
Yes! It is working with the new version, great!
Thank you
Max

Yihui Xie

unread,
Mar 27, 2015, 6:15:43 PM3/27/15
to Massimiliano Moro, shiny-discuss
Glad to know that.

Just realized I had it backwards in my previous reply: I meant to say
"switch from RJSONIO to jsonlite", instead of the other way around :(

Regards,
Yihui
Reply all
Reply to author
Forward
0 new messages