I am trying to take this basic working shiny app and modularize it. This works:
shinyApp(
  ui = fluidPage(
    DT::dataTableOutput("testTable"),
    verbatimTextOutput("two")
  ),
  server = function(input,output) {
    output$testTable <- DT::renderDataTable({
      mtcars
    }, selection=list(mode="multiple",target="row"))
    output$two <- renderPrint(input$testTable_rows_selected) 
  }
)
I want to make this a module that will work for any data.frame
# UI element of module for displaying datatable
testUI <- function(id) {
  ns <- 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 <- function(input,output,session,data) {
  ns <- session$ns
  output$testTable <- 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 <- callModule(test,"one",reactive(mtcars))
    output$two <- renderPrint(out()) 
  }
)
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.
Needed
return(reactive(input$testTable_rows_selected))
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With