gpt4 book ai didi

从 rhandsontable 对象中检索值(R,R Shiny )

转载 作者:行者123 更新时间:2023-12-01 12:25:57 26 4
gpt4 key购买 nike

我使用(很棒的)包 rhandsontable 稍后将包含在 中。 R Shiny 的网页。用户可以在某些地方单击,我想知道如何检索有关单击哪些行的信息。
这是一个示例,(在 R 终端中复制和粘贴):

library(rhandsontable)

## Create the dataset
min = c(1,seq(2,34,by=2))
kmh = c(0,seq(7,23,by=1))
mph = round( kmh / 1.609344, digits=0 )
stop.speed = rep(FALSE, length(min))
DF = data.frame(min, kmh, mph, stop.speed, stringsAsFactors = FALSE)

#plot the table
r = rhandsontable(DF, useTypes = TRUE)

我想把它转换成 R 目的:
hot_to_r(r)

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

最佳答案

这个问题已经 4 年了,但仍然与 rhandsontable 相关包用户。此外,上述 Lyx 提供的解决方案不再有效。以下是解决问题的简单方法。

rhandsontable object 是一个深度嵌套的列表。它的元素之一是 data元素,它本身嵌套在 x 下元素。但是,数据在json格式,但它可以很容易地转换为 data.frame通过使用 fromJSON() jsonlite 中的函数包裹。

library(rhandsontable)
library(jsonlite)

hands_on_table <- rhandsontable(mtcars)
data_frame <- fromJSON(hands_on_table$x$data)
head(data_frame)

mpg cyl disp hp drat wt qsec vs am gear carb
1 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
2 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
3 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
4 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
5 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
6 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1

编辑:

重要的是还要提到使用 hot_to_r 之间的主要区别。和 jsonlite::fromJSON是前者在应用程序运行时使用,后者仅在交互式 R session 中工作。

关于从 rhandsontable 对象中检索值(R,R Shiny ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39625954/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com