renderDataTable bootstrap breaks row_selected feature

81 views
Skip to first unread message

Rob

unread,
Nov 25, 2015, 7:45:41 AM11/25/15
to Shiny - Web Framework for R
Hello everyone,

this is my first post to this group, I hope you can understand my question and run my code. If not, please bump me (sorry, beginner).

I am producing a dynamic number of tabs, depending on the number of input tables I have. From there, I try to
grab dynamically the number of selected rows. So far so easy.
This works perfectly fine as long as I am not trying to make everything pretty. As soon as I 
enable the option style = 'bootstrap' in DT::renderDataTable the 
input$id1_rows_selected is always NULL (although it is created). 

Here is the (not so) minimal example:

#ui.R
library(shiny)
library(DT)

ui <- fluidPage(
  verbatimTextOutput("debug"),
  uiOutput('tabset')
)



#server.R
shinyServer(function(input, output) {
  dat <- list(cars,iris) #Produce my data sets
  output$tabset <- renderUI({
    tabs <- list()
    for(i in c(1,2)){
      id <- paste("id",i, sep="")
      tabs[[i]] <- tabPanel(title=id,DT::dataTableOutput(outputId=id)) #dynamic panels
    }
    do.call(tabsetPanel,c(tabs, id='Panel'))
  })
  
  lapply(1:2,function(i){
    id <- paste("id",i, sep="")
    output[[id]] <- DT::renderDataTable({
      dat[[i]]},
      extensions = c('Responsive','Scroller'),
      options=list(deferRender=TRUE, dom='T<"clear">fitrS', scrollY=540, searchHighlight = TRUE,
                   scrollCollapse=TRUE, autoWidth = TRUE,
                   columnDefs = list(list(width = '60%', targets = '_all',
                                          render = JS("function(data, type, row, meta) {",
                                                      "return type === 'display' && data.length > 5 ?",
                                                      "'<span title=\"' + data + '\">' + data.substr(0, 5) + '... </span>' : data;",
                                                      "}"
                                          )))),
      callback = JS('table.page(3).draw(false);'),
      escape=FALSE, rownames=TRUE,style = 'bootstrap' #- this somehow breaks rows_selected feature
      ,class = 'table-condensed', server=TRUE)
      })
  
  output$debug <- renderPrint({
    id <- input$Panel
    cat(input[[paste(id,"_rows_selected",sep="")]])
  })
})

Is there anything I am missing?

Any ideas are more than welcome.
 Rob


Alejandro Fernandez

unread,
Jul 7, 2016, 12:24:41 PM7/7/16
to Shiny - Web Framework for R
Hi just wondering if this ever got fixed?

Yihui Xie

unread,
Jul 7, 2016, 9:57:03 PM7/7/16
to Alejandro Fernandez, Shiny - Web Framework for R
Have you tried the development version of DT? https://github.com/rstudio/DT

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/cf03a7e8-8344-4c24-8115-80fff45ffcec%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Yihui Xie

unread,
Jul 7, 2016, 10:13:30 PM7/7/16
to Alejandro Fernandez, Shiny - Web Framework for R
Seems to be cross-posted to https://github.com/rstudio/DT/issues/317

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