rstudio/DT

Row selection for the server-side processing mode

yihui opened this issue · 5 comments

yihui commented

Moving @ReportMort's issue here from #50. Also mentioned by @frajuegies in #20.

yihui commented

Finally I managed to make row selection work for the server-side processing mode as well. Please update DT from Github, and see Section 2.1: http://rstudio.github.io/DT/shiny.html

@yihui Thanks for working on that, but the trick to do row selection by rowname doesn't really help with large tables when a user won't spend the time to click-select thousands of rows individually. In #50 I was expecting a fix that would make input$tbl_rows_all work with server-side processing so that user searches/filtering would bring back all of the table indices, not just the indices served to the client side. I guess that's just not possible with server=TRUE?

yihui commented

@ReportMort Unfortunately, you are right. That is not possible with server=TRUE. I have explained the reason at http://rstudio.github.io/DT/shiny.html

I do have the row indices inside the server-side processing function, though: https://github.com/rstudio/DT/blob/master/R/shiny.R#L168 The problem is DataTables does not seem to allow me to pass these indices back to the client: http://datatables.net/manual/server-side

@yihui I am curious to hear your thoughts about adding names to the filter input elements and then adding ChangeInput functions for when the values of those inputs change. Here is an example app I have working to show the filter inputted values and then parsing them to determine the server side row indices: https://reportmort.shinyapps.io/DT-filter-info/

It seems hacky, but wondering if you would be interested in adding more functionalities for the table inputs like this.

Adding Names to Input Elements
https://github.com/ReportMort/DT/blob/master/R/datatables.R#L368L377

A Few Lines Where I Add ChangeInput for Each Filter Input
https://github.com/ReportMort/DT/blob/master/inst/htmlwidgets/datatables.js#L88
https://github.com/ReportMort/DT/blob/master/inst/htmlwidgets/datatables.js#L169
https://github.com/ReportMort/DT/blob/master/inst/htmlwidgets/datatables.js#L229

yihui commented

@ReportMort That probably works, but is certainly inefficient, because you essentially did searching twice. What I would do is to check if it is possible to pass the row indices back from DT:::dataTablesFilter (even though DataTables does not make use of this information), and see if it is possible to use a success callback (http://datatables.net/reference/option/ajax http://api.jquery.com/jQuery.ajax/) to extract the indices, then pass to Shiny.onInputChange(). It looks like you are reasonably familiar with JavaScript, so please see if you can walk down this path.

BTW, the search items are available as input$foo_search_columns: http://rstudio.github.io/DT/shiny.html