Group 2: Exercise 1

Rewrite selectVarServer() so that both data and filter are reactive. Then use it with an app function that lets the user pick the dataset with the dataset module and filtering function using inputSelect(). Give the user the ability to filter numeric, character, or factor variables.

  1. Start changing the selectVarServer().
selectVarServer <- function(id,
                            data,
                            # Now filter is reactive
                            filter = reactive(is.numeric)) {
  
  
  stopifnot(is.reactive(data))
  # Now filter is reactive
  stopifnot(is.reactive(filter))
  
  
  moduleServer(id, function(input, output, session) {
    
    # We want to update the selector every time the data() or filter() change
    observe({
      # We need to have the filter before calling find_vars
      req(filter())
      updateSelectInput(session, "var", choices = find_vars(data(), filter()))
    })
    
    list(
      name = reactive(input$var),
      value = reactive(data()[[input$var]])
    )
  })
}