Selecting Multiple DataTable Rows using Shift+Click

820 views
Skip to first unread message

dansm...@gmail.com

unread,
Oct 29, 2015, 5:47:02 PM10/29/15
to Shiny - Web Framework for R
I was excited to see that the DT team has recently added support for using shift+click to select multiple rows in a datatable (http://editor.datatables.net/examples/simple/multiRow.html). Is there a way to use this feature with shiny-generated datatables?

In a basic example this the one below, multi-selection by clicking on one row at a time works perfectly, but enabling the shift-click behavior isn't as obvious to me.

# app.R
library(shiny)
shinyApp(
  ui = fluidPage(fluidRow(column(12, DT::dataTableOutput('tbl')))),
  server = function(input, output) {
    output$tbl = DT::renderDataTable(iris)
  }
)

Thanks!
  - Dan

dansm...@gmail.com

unread,
Oct 29, 2015, 8:17:24 PM10/29/15
to Shiny - Web Framework for R
I noticed that the reference manual for DT has a 'select.style' parameter that closely mirrors the 'selection' parameter of renderDataTable (http://datatables.net/reference/option/select.style). However, setting selection='os' causes termination with the error message "Error in gregexpr(calltext, singleline, fixed = TRUE) : regular expression is invalid UTF-8".

#app.R (this version does not run)
library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(fluidRow(column(12, DT::dataTableOutput('tbl')))),
  server = function(input, output) {
    output$tbl = DT::renderDataTable(iris, selection='os')
  }
)

#app.R (runs, but no shift-click behavior)
library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(fluidRow(column(12, DT::dataTableOutput('tbl')))),
  server = function(input, output) {
    output$tbl = DT::renderDataTable(iris, options=list(select.style='os'))
  }
)

Please let me know if you have any ideas. Thanks!

Yihui Xie

unread,
Oct 29, 2015, 11:21:37 PM10/29/15
to dansm...@gmail.com, Shiny - Web Framework for R
The DT package is using a custom implementation of row selections
instead of the official DataTables approach. We hope to catch up with
the official DataTables approach in the near future. For now, you
cannot use selection = 'os'. Sorry.

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/d21cc2c8-18b9-4981-b7db-b74fc29ae567%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages