title: DataTable row selection inside shiny module
body: <p>I am trying to take this basic working shiny app and modularize it. This works:</p>
  
  <pre><code>shinyApp(
    ui = fluidPage(
      DT::dataTableOutput("testTable"),
      verbatimTextOutput("two")
    ),
    server = function(input,output) {
      output$testTable &lt;- DT::renderDataTable({
        mtcars
      }, selection=list(mode="multiple",target="row"))
  
      output$two &lt;- renderPrint(input$testTable_rows_selected) 
    }
  )
  </code></pre>
  
  <p>I want to make this a module that will work for any data.frame</p>
  
  <pre><code># UI element of module for displaying datatable
  testUI &lt;- function(id) {
    ns &lt;- NS(id)
    DT::dataTableOutput(ns("testTable"))
  
  }
  # server element of module that takes a dataframe
  # creates all the server elements and returns
  # the rows selected
  test &lt;- function(input,output,session,data) {
    ns &lt;- session$ns
    output$testTable &lt;- DT::renderDataTable({
      data()
    }, selection=list(mode="multiple",target="row"))
  
    return(input[[ns("testTable_rows_selected")]])
  
  }
  
  shinyApp(
    ui = fluidPage(
      testUI("one"),
      verbatimTextOutput("two")
    ),
    server = function(input,output) {
      out &lt;- callModule(test,"one",reactive(mtcars))
      output$two &lt;- renderPrint(out()) 
    }
  )
  </code></pre>
  
  <p>This gives me errors saying I am trying to use reactivity outside of a reactive environment. If I eliminate the return statement, it runs. Is there anyway to return the rows selected from a datatable in a shiny module?  Any help would be appreciated.</p>