df=isolate(reactivePoll ())
来对数据框进行子集分析,因为reactivePoll会生成一个函数作为结果,然而isolate()
方法存在一个严重的问题:只有当闪亮应用程序打开时才会更新数据框,它只运行一次。
如何实时更新数据框对象,并能够对其进行子集分析,而不出现错误:Error in: object of type 'closure' is not subsettable
或 Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
在渲染函数中,reactivepoll函数非常适合实时显示表格,但是如何实现数据框的实时更新以及对其进行子集分析(例如 df$col1 df$col2 等)?
server(input,output,session){
df=reactivePoll(intervalMillis = 2000,session, checkFunc = function(){
QUERY1= "SELECT * FROM table"
df_rs = dbSendQuery(storiesDb,QUERY1)
dbFetch(df_rs)},
valueFunc =function (){
QUERY1= "SELECT * FROM table"
df_rs = dbSendQuery(storiesDb,QUERY1)
dbFetch(df_rs)
} )
dataframe= isolate(df()) # this approach makes the dataframe update only when the shiny app open.
}
尝试
1-我已经尝试使用dataframe=reactive({df ()})
,但在尝试对dataframe$col1进行子集分配时出现错误:Error in: object of type 'closure' is not subsettable
2-我已经尝试使用dataframe=df ()
, 但是出现了错误:Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
df()
。它 必须 在reactive
、eventReactive
、observe
、observeEvent
或其中一个render*
函数内部。这对于任何反应式表达式都是正确的,而不仅仅是从reactivePoll
返回的表达式。 - r2evans