'How to use the output from multiple "rounds" of selectizeInput() in R Shiny?

In my app, users upload experimental data. I'm trying to use selectizeInput() to allow users to select columns from the table to create different experimental groups, i.e. column 1 and 2 might be group 1, and column 3 is group 2. This is the code I have so far:

server(input, output) {
  values <- reactiveValues(
    numExpCr = 1
  )

  observeEvent(input$cr_exp, {
    values$numExpCr <- values$numExpCr + 1
  })

  output$cr_exp_gr <- renderUI({
    crExp_list <- lapply(1:values$numExpCr, function(i) {
      expname <- paste("Exp", i, sep="")
      selectizeInput("sel_exp", label = "Select samples for new biological group", choices = colnames(exp_dff()), options = list(create=TRUE), multiple = TRUE)
    })

    do.call(tagList, crExp_list)
  })
  sel <- reactive({
    req(input$sel_exp)
    return(exp_dff() %>% select(input$sel_exp))
  })

  output$sel <- renderDataTable(sel())
}

The problem I'm running into is that the function works fine for creating a single group, but I want users to be able to create multiple. I'm unsure of how to go about that though.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source