I was hoping to create a cross-session reactivePoll
which provides all shiny sessions with the same (expensive) DB query result by setting it's session argument to NULL
.
The example "Cross-session reactive file reader" given in ?reactiveFileReader
mentions:
In this example, all sessions share the same reader, so read.csv only gets executed once no matter how many user sessions are connected.
reactiveFileReader
is based on reactivePoll
so I thought the behaviour should be the same when setting session = NULL
.
However it seems reactivePoll
's valueFunc
still is executed for each session. Please see the following example:
library(shiny)
ui <- fluidPage(textOutput("time"))
server <- function(input, output, session) {
currentTime <- reactivePoll(
intervalMillis = 2000,
session = NULL,
checkFunc = function() {
print(paste("checkFunc session:", session$token))
as.numeric(Sys.time())
},
valueFunc = function() {
print(paste(as.character(Sys.time()), "session:", session$token))
as.character(Sys.time())
}
)
output$time <- renderText(currentTime())
}
shinyApp(ui, server)
Accordingly my question is:
Is it somehow possible to create a session independent reactive which is executed once per specified interval and feeds all sessions?
Btw. I'm aware that we can define global reactiveValues
each session can access as done here - but this approach would still fire my db-query for each session.
Here is a related SO post.