r - `rhandsontable` 包中的 `hot_to_r()` 函数在“正常”.R 脚本中不起作用 - 如何检查闪亮数据的方面?
问题描述
我试图了解如何hot_to_r()
转换使用rhandsontable()
. 我的目标是查看您在hot_to_r()
处理后获得的对象,以便调试闪亮的应用程序。
但是,您似乎无法在闪亮的应用程序之外执行此操作,即在 .R 脚本内。
[编辑] 进一步搜索将我引向这篇文章。我们确定您获得的对象与来自的对象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(测试)
(function (data, changes, params, ...) 中的错误:缺少参数“params”,没有默认值
我对闪亮很陌生;我错过了什么吗?
您无法hot_to_r()
在 .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
也是一种有效的方法。
推荐阅读
- java - 如何使用 Epson JavaPOS ADK 将位图转换为字节
- javascript - :after 元素上的 Angular MouseEvent 为 event.toElement.clientWidth 提供了错误的值
- javascript - 单选按钮值的返回类型是整数还是字符串
- javascript - 未捕获的 SyntaxError:使用 Rails 导入 Javascript 时出现意外标识符
- c# - C# 将字符串存储到外部文件的最简单方法
- c# - 样式设置的工具提示不起作用
- vba - 带有 SQL 插入的 VBA ADO Excel-2010 参考表
- python - sqlalchemy 通用日期时间算法
- json - Node.JS:如何抓取特定数据的 json 页面
- neo4j - 因果集群上只有 12 个事务/秒