如何设置reactive()Shiny中执行计算的优先级?例如,引用帮助文件中有一个priority选项observe()
priority
An integer or numeric that controls the priority with which this observer
should be executed. An observer with a given priority level will always execute
sooner than all observers with a lower priority level. Positive, negative,
and zero values are allowed.
Run Code Online (Sandbox Code Playgroud)
我希望通过让我的Shiny仪表板在将这些统计信息写入日志记录数据库之前显示一些摘要统计信息来应用此功能,这是一个示例
在server.R检索每个小时的数据
observe({
invalidateLater(3600000,session)
con <- dbConnect(PostgreSQL(), ...)
values$data = dbGetQuery(con, "select * from table;")
})
output$text = renderText({
temp = values$data
print(paste("the mean is", mean(temp)))
})
observe({
temp = values$data
dbWriteTable(con, paste0("Insert into table_means Values (", (mean(temp),");" ))
})
Run Code Online (Sandbox Code Playgroud)
在ui.R我打印数据的平均值.
我希望在将值写入我的sql数据库之前在UI中进行渲染
以下是一些相关问题:
我可能已经在这个问题中找到了答案:RshinypassingreactivetoselectInputchoices
**使用outputOptions它可以执行以下操作(从帮助文件粘贴):
## Not run:
# Get the list of options for all observers within output
outputOptions(output)
# Disable suspend for output$myplot
outputOptions(output, "myplot", suspendWhenHidden = FALSE)
# Change priority for output$myplot
outputOptions(output, "myplot", priority = 10)
# Get the list of options for output$myplot
outputOptions(output, "myplot")
## End(Not run)
Run Code Online (Sandbox Code Playgroud)
所以这允许你设置输出项的优先级,但它仍然没有告诉我这些优先级是如何相对于优先级的observe()。