Display R console log in shiny

1,546 views
Skip to first unread message

Sam H

unread,
Apr 29, 2015, 4:49:33 AM4/29/15
to shiny-...@googlegroups.com
How can I display R console log in shiny? I mean I want to see in shiny app what is going on, are there any errors, warning, what is print to R console log... Is there an elegant way to just simply display R console log?

I searched and results like this do not actually show m how to do what I want:
https://groups.google.com/forum/#!searchin/shiny-discuss/show$20r$20console/shiny-discuss/UK_GJyPAIFg/KDehmbyKDlUJ
http://stackoverflow.com/questions/28579711/display-r-console-logs-on-shiny-server

Adrian Duşa

unread,
Apr 29, 2015, 1:27:43 PM4/29/15
to shiny-...@googlegroups.com
On Wednesday, 29 April 2015 11:49:33 UTC+3, Sam H wrote:
How can I display R console log in shiny? I mean I want to see in shiny app what is going on, are there any errors, warning, what is print to R console log... Is there an elegant way to just simply display R console log?

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

Reply all
Reply to author
Forward
0 new messages