R Shiny - how to run a function with reactives just before session ends

Viewed 282

How can I run a function that depends on reactive values just before the session ends?

If I try using 'onStop' it doesn't work, see code below. Start the app, it loads a reactive value - how can this reactive value be used when ending the session?

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody()
)

server <- function(input, output, session) { 

  v <- reactiveValues(user = NULL)  # define the reactive value
  v$user <- "test_user" # populate the reactive value
  observe(cat(v$user)) # print the reactive value to console

  onStop(function(){
    cat(v$user) # this doesn't work - it errors when exiting the session
  })

}

shinyApp(ui, server)
0 Answers
Related