Is there a way to capture when a shiny application crashes/disconnects (i.e.: closes WebSocket connection) along with its traceback ~ message.
library(shiny)
ui <- fluidPage(
actionButton("crash", "Crash")
)
server <- function(input, output, session) {
session$onEnded(function(){
print(warnings()) # nothing
print(traceback()) # NULL
print(shiny:::.globals$deepStack) # NULL
})
observeEvent(input$crash, {
print(error) # no error object: disconnects
})
}
shinyApp(ui, server)
Nothing I tried worked (see above).
It seems {shiny} does a lot of manipulation of the stacktrace, perhaps that is the reason?
in relation to the related thread; I did raise an issue on the shiny/github enquiring as to best practice and how to work in this space; but seem to have no traction; perhaps if others with similar concerns add to my issue this would raise its profile.
How to log shiny::devmode() output ? · Issue #3677 · rstudio/shiny (github.com)
After setting options(shiny.fullstacktrace = TRUE) the traceback() call no longer results in NULL:
library(shiny)
options(shiny.fullstacktrace = TRUE)
ui <- fluidPage(
actionButton("crash", "Crash")
)
server <- function(input, output, session) {
session$onEnded(function(){
cat("\nSTART traceback ---------------------------------------------------------\n")
print(traceback())
cat("\nEND traceback -----------------------------------------------------------\n")
})
observeEvent(input$crash, {
print(error) # no error object: disconnects
})
}
shinyApp(ui, server)
I don't know what version of shiny you are on but this is not working for me.
START traceback ---------------------------------------------------------
No traceback available
NULL
END traceback -----------------------------------------------------------
In fact, to the best of my understanding, this is the default already it seems, see code.
The traceback is pushed to .globals$deepStack (see my question).
By the time onEnded or onStop runs this has been cleared, hence the issues.
You are right - it is populated only on the second run (shiny 1.7.3 - latest CRAN).