(Cross post from the shiny-discuss Google group since I got 0 answers).
I don't understand R's message vs cat vs print vs etc. too deeply, but I'm wondering if it's possible to capture messages and who them in a shiny app?
Example: the following app can capture cat statements (and print statements as well) but not message statements
runApp(shinyApp(
ui = fluidPage(
textOutput("test")
),
server = function(input,output, session) {
output$test <- renderPrint({
cat("test cat")
message("test message")
})
}
))
Link to original question: https://groups.google.com/forum/#!topic/shiny-discuss/UCacIquFJQY
Thanks
I know this isn't nearly as elegant, but I worked around a bit similar problem using
capture.output
; sadlysink
doesn't allow simultaneous capture of messages and output though. You don't get them in the original order, but you can extract both streams at least (here turned to HTML):Output:
Perhaps in the case if user wants to capture both but also separate them, this will provide a handy work-around. (Your
shinyjs
package seems neat, need to take a look at it!)Yihui suggested I use
withCallingHandlers
, and that indeed let me to a solution. I wasn't quite sure how to use that function in a way that would do exactly what I needed because my problem was that I had a function that printed out several messages one at a time and using a naive approach only printed the last message. Here is the my first attempt (which works if you only have one message to show):Notice how only
two\n
gets outputted. So my final solution was to use thehtml
function fromshinyjs
package (disclaimer: I wrote that package), which lets me change or append to the HTML inside an element. It worked perfectly - now both messages got printed out in real-time.