This is what I do, in the server.R, let's say I have a function called myfunction() which displays something on the console. If for any reason there is an error we could capture it and pass it to the webpage.
textoutput <- capture.output(tryCatch(myfunction(...) , error = function(e) e)
if (any(error <- grepl("Error", textoutput))) {
textoutput <- paste0("Error:", unlist(strsplit(textoutput[which(error)], split=":"))[2])
}
Then pass textoutput to the webpage via renderPrint() or session$sendCustomMessage().
See demo(error.catching) in R, where there is a function to capture both error and warnigns:
tryCatch.W.E <- function(expr) {
W <- NULL
w.handler <- function(w) { # warning handler
W <<- w
invokeRestart("muffleWarning")
}
list(value = withCallingHandlers(tryCatch(expr, error = function(e) e),
warning = w.handler),
warning = W)
}
I hope this helps,
Adrian