在 Shiny 中使用 rhandsontable 时出错

Error using rhandsontable in Shiny

我在闪亮的应用程序中观察到 rhandsontable 的一些奇怪行为。在这个简单的示例中,如果某些事件发生,我将 data.frame 分配给 reactiveValues 元素。然后数据显示在 rhandsontable 中。但是当我更改 table 的某些条目时,函数 hot_to_r 失败并显示: Error in seq.default: argument 'length.out' must be of length 1

奇怪的是,错误仅在我使用 iris 时发生,但在我使用 iris[1:50, ] 时不会发生,这应该是相同的。有人知道如何解决这个问题吗?

(在单击 actionButton 之前 values$data 仍然是 NULL 时还有另一个错误。我知道这一点,但这与问题无关。)

library(shiny)

ui <- fluidPage(
  actionButton("click", "click"),
  rHandsontableOutput("table")
)

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

  values <- reactiveValues(data = NULL)

  observeEvent(input$click, {
    values$data <- iris # with iris[1:50, ] no error appears
  })

  output$table <- renderRHandsontable({
    rhandsontable(t(values$data))
  })

  observe({
    if (!is.null(input$table$changes$changes)) {
      table_data <- hot_to_r(input$table)
      print(table_data)
    }
  })

}

shinyApp(ui, server)

@BigDataScientist 在做某事,colnames(t(iris))NULL,而 colnames(t(iris[1:50,])) 不是。这对我来说是个谜,但防止空值应该可以解决您的问题。在 rhandsontable 的调用中使用一些东西应该可以解决问题。使用

rhandsontable(data.frame(t(values$data)))

对我有用。