0

I am using renderUI to create dynamic textboxes and dropdown on my UI. I want to capture the event of change in the textbox / dropdown and modify the data frame

Below is the code to create the UI

server <- function(input, output, session){

  output$fileContent <- renderTable({
    inFile <- input$csvFile
    csvContent <- read.csv(inFile$datapath)
    output$summary <- renderPrint({str(csvContent)})
    allColumns <- names(csvContent)
    types <- sapply(csvContent, class)
    w <- ""
    for (i in 1:length(allColumns)){
      w <- paste(w, selectInput(paste("inp",allColumns[i], sep = "_"), allColumns[i],choices = c("factor","integer","logical","character", "Date"), selected = types[i], width = 200))
    }
    output$columns <- renderUI({ HTML(w) })
    return (head(csvContent))
  })

Desired output -

The code above renders the textboxes as desired on the UI but does not capture event on change of value in textbox. Since the controls are dynamic, I can not code for static capture event as the control name would be generated dynamically

Ankit
  • 6,388
  • 8
  • 54
  • 79
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. What exactly is the behavior you want? Try making an example that doesn't rely on a user uploading a file so we can more easily help. – MrFlick Feb 05 '19 at 21:09
  • um, just a side note: You have `renderUI()` within a `renderTable()`,...is that on purpose? Concerning your question: What you could do is to save the names of your dynamic gen. inputs `paste("inp",allColumns[i], sep = "_")` in `reactiveValues()`,.... and get the names from there,... If you need more concrete help you should probably follow MrFlick´s advice,... – Tonio Liebrand Feb 05 '19 at 22:45
  • Thanks for the response. How do I add dynamic controls reactiveValues? – Ankit Feb 06 '19 at 00:26

1 Answers1

0

Got the answer on https://gist.github.com/mine-cetinkaya-rundel/0fe2a9830f7151e72053239e73350592

It has sample application that works fine with dynamic UI

Ankit
  • 6,388
  • 8
  • 54
  • 79