needRhelp
needRhelp

Reputation: 3148

Error using rhandsontable in Shiny

I've observed some strange behaviour of rhandsontable in a shiny app. In this simple example I am assigning a data.frame to a reactiveValues element if some event happens. The data is then shown in a rhandsontable. But when I change some entry of the table the function hot_to_r fails with: Error in seq.default: argument 'length.out' must be of length 1

Strangely the error only happens if I use iris, but not when I use iris[1:50, ], which should be identical. Does somebody have an idea, how to fix this?

(There is another error when values$data is still NULL before the actionButton is clicked. I'm aware of this, but this is not relevant for the question.)

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)

Upvotes: 0

Views: 1193

Answers (1)

chepyle
chepyle

Reputation: 996

@BigDataScientist is on to something, colnames(t(iris)) is NULL, whereas colnames(t(iris[1:50,])) is not. That is a mystery to me, but preventing that nullness should resolve your problem. Using something in the call to rhandsontable should do the trick. Using

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

worked for me.

Upvotes: 1

Related Questions