我在文件夹中有一些json文件,并希望将数据用于条形图。我想要一个一个 reactPoll函数在文件更改时读取数据。当前,它正在处理许多reactPoll调用和函数,即,每个文件都有一个调用和一个函数。这个问题似乎与this one非常相似。但是由于此错误,我无法实现:
错误:“ closure”类型的对象不可子集化。
这是我所做的:
功能:
my.reactivePoll <- function(session, table_name, timeout = 1000)
{
getJsonData <- reactivePoll(1000, session,
checkFunc = function() {
if (file.exists(table_name))
file.info(table_name)$mtime[1]
else
""
},
valueFunc = function() {
read_json(table_name)
})
getJsonData
}
带有调用的服务器功能:
server <- function(input, output, session) {
#product_path is e.g.: "C:\\Users\\...\\json\\Test_01.json"
#later I want to implement a list of files, but for now it would be sufficient to have let's say 10 calls (10 lines of code) for 10 files, but only one function
d <- my.reactivePoll(session, product_path)
#the error occurs in the following line:
df <- data.frame(substance=unlist(d$substance), level=unlist(d$level))
# here I want to plot the data
ggplot(data=df, aes(x=substance, y=level)) +
geom_bar(color="black", fill="forestgreen", stat="identity")
}
当我绘制d时,我得到一个令人困惑的反馈:
reactive({
rv$cookie
valueFunc()
})