Shiny rHandsontable下拉列表在应用程序中未保留编辑的问题?

Shiny rHandsontable下拉列表在应用程序中未保留编辑的问题?,shiny,rhandsontable,Shiny,Rhandsontable,我构建了一个闪亮的应用程序,它会提示用户输入动态添加为rHandsontable行的内容。用户可以添加行、编辑行,然后添加更多行。应用程序正在正常工作,但创建为hot\u cols且类型为“dropdown”的列除外。用户对这些列所做的任何编辑在下次添加行时都不会保留,但所有其他编辑都会保留 下面是我的应用程序。对word列的编辑将被保留,但对hot\u col()创建的color列的编辑不会被保留 库(闪亮) 图书馆(rhandsontable) 图书馆(dplyr) ui有两点需要调整: 列

我构建了一个闪亮的应用程序,它会提示用户输入动态添加为rHandsontable行的内容。用户可以添加行、编辑行,然后添加更多行。应用程序正在正常工作,但创建为
hot\u col
s且类型为“dropdown”的列除外。用户对这些列所做的任何编辑在下次添加行时都不会保留,但所有其他编辑都会保留

下面是我的应用程序。对
word
列的编辑将被保留,但对
hot\u col()
创建的
color
列的编辑不会被保留

库(闪亮)
图书馆(rhandsontable)
图书馆(dplyr)

ui有两点需要调整:

  • 列“颜色”应初始化为字符
  • observeEvent
  • 以下是您的代码的工作版本:

    library(shiny)
    library(rhandsontable)
    library(dplyr)
    
    ui <- fluidPage(
      fluidRow(
        textAreaInput('wordlines', "Enter words separated by newlines"),
        actionButton('submit', "Submit Words"),
        p(),
        rHandsontableOutput('hot')
      )
    )
    
    server <- function(input, output, session) {
    
      colors <- c("red", "orange", "yellow", "green", "blue", "indigo", "violet")
    
      build_df <- function(input) {
        data.frame(
          word = unlist(strsplit(input$wordlines, "\n")),
          number = sample(100, 1),
          color = NA_character_,
          stringsAsFactors = FALSE
        )
      }
    
      values <- reactiveValues()
    
      observeEvent(input$submit, {
    
        req(input$wordlines)
    
        if(input$submit == 1) { # if button pressed the first time
          values$df <- build_df(input)
        } else {
          tmp <- hot_to_r(input$hot)
          values$df <- bind_rows(tmp, build_df(input)) # add new rows to values$DF
        }
    
        updateTextAreaInput(session, 'wordlines', value = "") # clear textAreaInput
      })
    
      output$hot <- renderRHandsontable({
        req(values$df)
        rhandsontable(values$df, overflow = 'visible') %>% hot_col(col = "color", type = "dropdown", source = colors) # dropdown column which, when edited, should preserve those edits through future adding of rows ('submit' button presses)
      })
    
    }
    
    # Run the application 
    shinyApp(ui = ui, server = server)
    
    库(闪亮)
    图书馆(rhandsontable)
    图书馆(dplyr)
    用户界面
    
    library(shiny)
    library(rhandsontable)
    library(dplyr)
    
    ui <- fluidPage(
      fluidRow(
        textAreaInput('wordlines', "Enter words separated by newlines"),
        actionButton('submit', "Submit Words"),
        p(),
        rHandsontableOutput('hot')
      )
    )
    
    server <- function(input, output, session) {
    
      colors <- c("red", "orange", "yellow", "green", "blue", "indigo", "violet")
    
      build_df <- function(input) {
        data.frame(
          word = unlist(strsplit(input$wordlines, "\n")),
          number = sample(100, 1),
          color = NA_character_,
          stringsAsFactors = FALSE
        )
      }
    
      values <- reactiveValues()
    
      observeEvent(input$submit, {
    
        req(input$wordlines)
    
        if(input$submit == 1) { # if button pressed the first time
          values$df <- build_df(input)
        } else {
          tmp <- hot_to_r(input$hot)
          values$df <- bind_rows(tmp, build_df(input)) # add new rows to values$DF
        }
    
        updateTextAreaInput(session, 'wordlines', value = "") # clear textAreaInput
      })
    
      output$hot <- renderRHandsontable({
        req(values$df)
        rhandsontable(values$df, overflow = 'visible') %>% hot_col(col = "color", type = "dropdown", source = colors) # dropdown column which, when edited, should preserve those edits through future adding of rows ('submit' button presses)
      })
    
    }
    
    # Run the application 
    shinyApp(ui = ui, server = server)