`rhandsontable` 包中的 `hot_to_r()` 函数在 "normal" .R 脚本中不起作用 - 你如何检查 shiny 中数据的方面?

`hot_to_r()` function from `rhandsontable` package not working inside a "normal" .R script - how do you check the aspect of your datas inside shiny?

我想了解如何 hot_to_r() 转换使用 rhandsontable() 获得的列表对象。我的目标是查看您在 hot_to_r() 进程之后获得的对象,以便调试闪亮的应用程序。

但是,您似乎无法在闪亮的应用程序之外执行此操作 ,即在 .R 脚本中

[编辑] 进一步搜索让我找到 post。 我们确定您从 fromJSON() 获得的对象与从 hot_to_r()

获得的对象相同吗

这是一个 .R 脚本,我试图用它来查看 hot_to_r() 的输出:

library(rhandsontable)
library(tidyverse)
library(jsonlite)

# dummy dataframe
df = data.frame(id = c("a", "b"),
                val = c(0.75, 0.25))

# convert it to a "rhansontable" object
test = rhandsontable(df)

# try to convert it back to a dataframe but it doesn't work
test_hot = hot_to_r(test)

# however, this works but I am not sure if test_json is the same as test_hot
test_json = fromJSON(test$x$data)

test_hot = hot_to_r(test) 导致此错误:

test_df = hot_to_r(test)

Error in (function (data, changes, params, ...) : argument "params" is missing, with no default

我对闪亮很陌生;我错过了什么吗?

无法在 .R 脚本中hot_to_r()工作是否正常?

如果是,您如何在闪亮的应用程序中检查数据的“方面”? 总体目标是使用用户填写的rhandsontable 进行计算。我想将此对象转换为数据框,以便进行正确的修改以获得“整洁”的数据集。

hot_to_r 旨在与闪亮的输入一起使用(其中包含错误消息中提到的 params 参数)。

为了在闪亮的上下文中进行调试,我建议使用 browser()

请检查以下内容:

library(rhandsontable)
library(shiny)

ui <- fluidPage(
  rHandsontableOutput("myTable")
)

server <- function(input, output, session) {
  # dummy dataframe
  df = data.frame(id = c("a", "b"),
                  val = c(0.75, 0.25), stringsAsFactors = FALSE)

  # convert it to a "rhansontable" object
  output$myTable <- renderRHandsontable({rhandsontable(df)})

  observeEvent(input$myTable, {
    test_df = hot_to_r(input$myTable)
    print(test_df)
    # browser() # uncomment for debugging
  })

}

shinyApp(ui, server)

但是,fromJSON 也是一种有效的方法。