我想在shiny中使用RHandsontable执行reactivity,它将从表中获取输入并执行计算。然而,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)发布于 2019-03-28 23:42:36
我发现了问题。hot_to_r()必须有dataframe输入,所以下面的代码可以工作
tt <- data.frame('col1' = c(10,30), 'col2' = c(20,40))
hot_to_r(tt)https://stackoverflow.com/questions/55328071
复制相似问题