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

Ika*_*ka8 1 r shiny

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

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

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.

Vic*_*orp 6

您必须在非反应性上下文中使用isolate来访问reactiveValues(例如session):

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)
Run Code Online (Sandbox Code Playgroud)