Description Usage Arguments Value See Also Examples
This function registers callback functions that are invoked when the
application exits (when runApp()
exits), or after each user
session ends (when a client disconnects).
1 | onStop(fun, session = getDefaultReactiveDomain())
|
fun |
A function that will be called after the app has finished running. |
session |
A scope for when the callback will run. If |
A function which, if invoked, will cancel the callback.
onSessionEnded()
for the same functionality, but at
the session level only.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | ## Only run this example in interactive R sessions
if (interactive()) {
# Open this application in multiple browsers, then close the browsers.
shinyApp(
ui = basicPage("onStop demo"),
server = function(input, output, session) {
onStop(function() cat("Session stopped\n"))
},
onStart = function() {
cat("Doing application setup\n")
onStop(function() {
cat("Doing application cleanup\n")
})
}
)
}
# In the example above, onStop() is called inside of onStart(). This is
# the pattern that should be used when creating a shinyApp() object from
# a function, or at the console. If instead you are writing an app.R which
# will be invoked with runApp(), you can do it that way, or put the onStop()
# before the shinyApp() call, as shown below.
## Not run:
# ==== app.R ====
cat("Doing application setup\n")
onStop(function() {
cat("Doing application cleanup\n")
})
shinyApp(
ui = basicPage("onStop demo"),
server = function(input, output, session) {
onStop(function() cat("Session stopped\n"))
}
)
# ==== end app.R ====
# Similarly, if you have a global.R, you can call onStop() from there.
# ==== global.R ====
cat("Doing application setup\n")
onStop(function() {
cat("Doing application cleanup\n")
})
# ==== end global.R ====
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.