title: RStudio Shiny list from checking rows in dataTables
body: <p>I would like to have a working example similar to this:
  <a href="https://demo.shinyapps.io/029-row-selection/" rel="noreferrer">https://demo.shinyapps.io/029-row-selection/</a></p>
  
  <p>I tried the example in my Shiny server running <code>Shiny Server v1.1.0.10000</code>, <code>packageVersion: 0.10.0</code> and <code>Node.js v0.10.21</code>, but it is not working even if I load the js and css files from the website. It simply does not select rows from the table:</p>
  
  <pre class="lang-r prettyprint-override"><code># ui.R
  library(shiny)
  
  shinyUI(fluidPage(
    title = 'Row selection in DataTables',
    tagList(
            singleton(tags$head(tags$script(src='//cdn.datatables.net/1.10.2/js/jquery.dataTables.js',type='text/javascript'))),
            singleton(tags$head(tags$script(src='//cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css',type='text/css')))
          ),
    sidebarLayout(
      sidebarPanel(textOutput('rows_out')),
      mainPanel(dataTableOutput('tbl')),
      position = 'right'
    )
  ))
  
  # server.R
  library(shiny)
  
  shinyServer(function(input, output) {
    output$tbl &lt;- renderDataTable(
      mtcars,
      options = list(pageLength = 10),
      callback = "function(table) {
        table.on('click.dt', 'tr', function() {
          $(this).toggleClass('selected');
          Shiny.onInputChange('rows',
                              table.rows('.selected').indexes().toArray());
        });
      }"
    )
    output$rows_out &lt;- renderText({
      paste(c('You selected these rows on the page:', input$rows),
            collapse = ' ')
    })
  })
  </code></pre>
  
  <p>I then tried to do this from a different example that was using radio buttons to re-sort the rows.</p>
  
  <p>In my modified example, I want to produce a list of ids from the selected checkbox buttons of the dataTables table shown in the webpage. E.g., selecting some rows from the first 5, I want my textbox to be: <code>1,3,4</code> corresponding to the <code>mymtcars$id</code> column I added to mtcars. I then plan to link an action to the values of the textbox.</p>
  
  <p>I have it almost there in this example, but checking the boxes does not update the list in the textbox. Differently to the example shinyapp, I would like my checkboxes to keep the selection status if the table is resorted. This may be the tricky part, and I am not sure how to do it. I would also like to add a "Select/Unselect all" textbox on the top left corner of the table, that selects/unselects all boxes in the table. Any ideas?</p>
  
  <p><img src="https://i.stack.imgur.com/RXe6S.jpg" alt="enter image description here"></p>
  
  <pre class="lang-r prettyprint-override"><code># server.R
  library(shiny)
  
  mymtcars = mtcars
  mymtcars$id = 1:nrow(mtcars)
  
  shinyServer(function(input, output, session) {
  
        rowSelect &lt;- reactive({
          if (is.null(input[["row"]])) {
              paste(sort(unique(rep(0,nrow(mymtcars)))),sep=',')
          } else {
              paste(sort(unique(input[["row"]])),sep=',')
          }
        })
  
    observe({
        updateTextInput(session, "collection_txt",
          value = rowSelect()
          ,label = "Foo:"
        )
    })
  
        # sorted columns are colored now because CSS are attached to them
        output$mytable = renderDataTable({
                addCheckboxButtons &lt;- paste0('&lt;input type="checkbox" name="row', mymtcars$id, '" value="', mymtcars$id, '"&gt;',"")
                    #Display table with checkbox buttons
                    cbind(Pick=addCheckboxButtons, mymtcars[, input$show_vars, drop=FALSE])
            }, options = list(bSortClasses = TRUE, aLengthMenu = c(5, 25, 50), iDisplayLength = 25))
  
  })
  
  
  # ui.R
  library(shiny)
  
  mymtcars = mtcars
  mymtcars$id = 1:nrow(mtcars)
  
  shinyUI(pageWithSidebar(
        headerPanel('Examples of DataTables'),
        sidebarPanel(
                checkboxGroupInput('show_vars', 'Columns to show:', names(mymtcars),
                                                          selected = names(mymtcars))
              ),
        mainPanel(
                           dataTableOutput("mytable")
        ,textInput("collection_txt",label="Foo")
                )
        )
  )
  </code></pre>