Shiny Server - how to use session$onSessionEnded()

Hi I don't know how you construct the shinyActivityTmpFile file, but for using onSessionEnded you can look at this exemple, it write in a file the datetime when an app is launched and when the app is closed :

library("shiny")
ui <- fluidPage(
  "Nothing here"
)
server <- function(input, output, session) {
  # This code will be run once per user
  users_data <- data.frame(START = Sys.time())

  # This code will be run after the client has disconnected
  session$onSessionEnded(function() {
    users_data$END <- Sys.time()
    # Write a file in your working directory
    write.table(x = users_data, file = file.path(getwd(), "users_data.txt"),
                append = TRUE, row.names = FALSE, col.names = FALSE, sep = "\t")
  })
}
shinyApp(ui = ui, server = server)

If you use a server with authentication, you can retrieve the username with :

users_data <- data.frame(USERS = session$user, START = Sys.time())