App 2: Extracting a numeric variable (SERVER)

  1. Create a function to list all columns that meet the condition passed to the filter argument as a function.
find_vars <- function(data, filter) {
  names(data)[vapply(data, filter, logical(1))]
}
  1. Update the select input element in the UI with columns that meet the condition and extract the selected column from the reactive dataset.
selectVarServer <- function(id, data, filter = is.numeric) {
  
  moduleServer(id, function(input, output, session) {
    
    observeEvent(data(), {
      updateSelectInput(session, "var", choices = find_vars(data(), filter))
    })
    
    reactive(data()[[input$var]])
  })
  
}