0

我正在使用 renderUI 在我的 UI 上创建动态文本框和下拉菜单。我想在文本框/下拉列表中捕获更改事件并修改数据框

下面是创建 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))
  })

所需的输出 -

上面的代码在 UI 上根据需要呈现文本框,但不会捕获文本框中值更改的事件。由于控件是动态的,我不能为静态捕获事件编码,因为控件名称将动态生成

4

1 回答 1

0

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

It has sample application that works fine with dynamic UI

于 2019-02-06T01:55:13.340 回答