DT::Datatable render speed

1,456 views
Skip to first unread message

ShinyIsCool

unread,
Feb 7, 2015, 10:19:53 AM2/7/15
to shiny-...@googlegroups.com
Hello -- in the code below I am trying to render a dataframe with several records using the old and new datatable elements.  The old datatable renders immediately.  The new one takes 4-5 seconds.  You will need to comment/uncomment sections of the code and run them separately.  Use the slider bar to make a bigger df and obviously the times increase even more, although on my machine the refresh for the old datatable is still pretty much instantaneous.  Thanks.


==============app.R========================
require(shiny)
#require(DT)

MkDF <- function(nr) {
    data.frame(
        varid=sample(10000000:20000000,nr,replace=FALSE),
        description=sapply(1:nr, function(x) paste(sample(letters,10),collapse="")),
        value1=round(runif(nr),3), value2=round(runif(nr),3)
    )
}

server <- function(input, output) { 
    ds <- reactive({ MkDF(strtoi(input$nrows)) })
    output$tbl = renderDataTable({ ds() }, options=list(pageLength=10, lengthChange=FALSE, searching=FALSE))
   
    #ds <- reactive({ MkDF(strtoi(input$nrows)) })
    #output$tbl = DT::renderDataTable({ DT::datatable(ds(), options=list(pageLength=10, lengthChange=FALSE, searching=FALSE)) })
}

ui <- shinyUI(
    navbarPage("Example",
        tabPanel("DT - Old",
            sliderInput("nrows", label=h6("Number Of Rows"), min=20000, max=30000, value=24000, step=1000, ticks=FALSE),
            fluidRow(  column(offset=2, width=4, dataTableOutput('tbl')) )
        )
        #tabPanel("DT - New",
        #    sliderInput("nrows", label=h6("Number Of Rows"), min=20000, max=30000, value=24000, step=1000, ticks=FALSE),
        #    fluidRow( column(offset=2, width=4, DT::dataTableOutput('tbl') ) )
        #)
    )
)

shinyApp(ui=ui, server=server)
===========================================

ShinyIsCool

unread,
Feb 7, 2015, 10:33:26 AM2/7/15
to shiny-...@googlegroups.com
One other thing -- I was tinkering with the options to see if there is a combination which would make this faster.

By setting  server=TRUE  (or serverSide=TRUE inside the options -- same thing), a box pops up which says "DataTables warning: table id ...   Invalid JSON response ..."

It's not that I need serverside processing...I was just trying to see how to speed it up.

Oliver Gjoneski

unread,
Feb 7, 2015, 12:06:01 PM2/7/15
to shiny-...@googlegroups.com
Server-side processing is a huge performance boon when displaying tables with a large number of rows - you are right to explore this option.

However using server-side processing within shiny is not as simple as just flipping the parameter to true.

Section 3.2 is what you are looking for here: http://rstudio.github.io/DT/#server-side-processing

ShinyIsCool

unread,
Feb 7, 2015, 12:23:29 PM2/7/15
to shiny-...@googlegroups.com
Thanks for your response, Oliver.  I looked at the server-side script on datatable.net; being a Pythonista, it is nice that people have posted server-side code for doing this in Python (http://datatables.net/forums/discussion/13679/working-code-for-server-side-paging-filtering-sorting-for-python-flask-mongodb).

My original question remains -- the comparison with the old renderDataTable in shiny (see my example in the OP) shows a big difference in render speed.  Is that expected?

Vincent

unread,
Feb 7, 2015, 12:59:34 PM2/7/15
to shiny-...@googlegroups.com
I think the default in the old version was server-side processing and now it is client-side. That may explain the difference.

ShinyIsCool

unread,
Feb 7, 2015, 1:51:36 PM2/7/15
to shiny-...@googlegroups.com
THANK YOU for your responses...I re-read section 3 on that page (specifically section 3.2.2) and got it working.  It is now just as fast as the old datatable because of the server-side processing!

Yihui Xie

unread,
Feb 8, 2015, 5:38:38 AM2/8/15
to ShinyIsCool, shiny-discuss
Vincent was absolutely correct (thanks!) that shiny::renderDataTable()
only implemented server-side processing, and the new DT package uses
client-side processing by default. You can make use of server-side
processing for DT if you can provide a server-side processing function
(as the example on the DT website shows). Please also note that the
server-side processing code here does not even have to be implemented
in R.

Regards,
Yihui
> --
> 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/cc83a419-fcba-43c6-b374-f9a781fc02df%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

mbh

unread,
Mar 23, 2015, 12:11:31 PM3/23/15
to shiny-...@googlegroups.com, vijay...@gmail.com
Hello Yihui,

Is there a way to disable the warning popup I get when I'm executing :
shiny::runApp(system.file('examples', 'DT-shiny', package = 'DT'))
? Thanks for your help,

Matt

Yihui Xie

unread,
Mar 23, 2015, 6:14:06 PM3/23/15
to mbh, shiny-discuss, Vijay Nori
Can you install the development versions of shiny and DT, and see if
the warning is still there? Thanks!

devtools::install_github(c('rstudio/shiny', 'rstudio/DT'))

Regards,
Yihui

mbh

unread,
Mar 24, 2015, 5:52:19 AM3/24/15
to shiny-...@googlegroups.com, matthie...@bluestone.fr, vijay...@gmail.com
Yes it works, thank you Yihui. Will this be fixed soon in CRAN versions ? 

Yihui Xie

unread,
Mar 24, 2015, 10:00:01 PM3/24/15
to mbh, shiny-discuss, Vijay Nori
Glad to know that. Thanks! I do not have a specific date for the
release at the moment, but I guess it won't be too long.

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