watchEvent和RHandsontable

时间:2019-03-24 20:07:31

标签: shiny shinydashboard rhandsontable

我想用闪亮的RHandsontable进行反应,这将从表中获取输入并执行计算。但是,hot_to_r发生错误。但是对于我的一生来说,我看不出问题出在哪里,因为这对我来说早已奏效。我收到错误消息:

Warning: Error in genColHeaders: Change no recognized:afterChange

代码如下:

library(shinydashboard)
library(rhandsontable)
ui <- dashboardPage(
  dashboardHeader(title = "App"),
  dashboardSidebar(disable = TRUE),
  dashboardBody(skin = "blue",
  box(
    rHandsontableOutput("tt"),
    actionButton(inputId = "sim", label = "Simulate")
  ),
  box(
    tableOutput("result"),
    span(textOutput("error"), style="color:red")
    )
  )
)

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

    tt <- matrix(as.integer(c(10, 20, 30, 40)), nrow = 2, byrow = TRUE)

    output$tt <- renderRHandsontable(rhandsontable(tt, readOnly = FALSE))

    observeEvent( input$sim, {

      tt_input <- hot_to_r(input$tt)

      result <- tryCatch(
       {
        log(tt_input)
       }, warning = function(w){
           return(w$message)
       }, error = function(e){
           return(e$message)
         }
       )

      if(!is(result, "character")){
        output$result <- renderTable(result, rownames = TRUE)
        output$error <- renderText("")
      } else {
        output$error <- renderText({
               result
        })
        output$result <- renderTable(matrix())
      }

    })

}

shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:0)

我发现了问题。 hot_to_r()必须具有数据帧输入,因此以下工作

tt <- data.frame('col1' = c(10,30), 'col2' = c(20,40))

hot_to_r(tt)
相关问题