Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I access to session values in onSessionEnded event in shiny?

Tags:

r

shiny

Can I access to session values from onStop / onSessionEnded functions?

onStop(function() {
            cat(file = stderr(), paste(app, session$clientData$url_protocol, sep = ' - '))
        })

That code gives me this error: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context.

There is a way to get session values inside this functions?

If not, there is a way to execute a function just before the session is ended?

Thanks.

like image 210
Ika8 Avatar asked Dec 24 '22 08:12

Ika8


1 Answers

You'll have to use isolate to access reactiveValues (such as session) in a non reactive context :

library(shiny)

ui <- fluidPage(
  "Just close app after launch"
)

server <- function(input, output, session) {
  onStop(fun = function() {
    str(isolate(session$clientData$url_protocol))
  })
}

shinyApp(ui, server)
like image 143
Victorp Avatar answered Mar 09 '23 01:03

Victorp