我试图了解如何转换hot_to_r()
rhandsontable()
获得的列表对象。我的目标是查看您在hot_to_r()
进程后获得的对象,以便调试一个闪亮的应用程序。
但是,您似乎无法在闪亮的应用程序外部执行此操作,即在.R 脚本。
[编辑]搜索进一步将我带到这篇文章。 我们确定您从fromJSON()
获得的对象与从hot_to_r()
获得的对象相同吗?
这是一个.我试图用来查看hot_to_r()
输出的 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(测试(
(函数(数据、更改、参数等(中的错误 :参数"参数"缺失,没有默认值
我对闪亮很陌生;我错过了什么吗?
您无法hot_to_r()
在 .R 脚本?
如果是,您如何在闪亮的应用程序内检查数据的"方面"? 总体目标是使用用户填充的可操作进行计算。我想将此对象转换为数据帧,以便进行正确的修改以获得"整洁"的数据集。
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
也是一种有效的方法。