Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress warning message in R console of shiny

Tags:

r

shiny

We developed a shiny application. It was showing some warning messages, we never bothered it, because the application is working fine. But, we can't distribute the application with warning message appearing in the console. Now my question is, how to suppress the warning message in R console, when shiny application is running.

like image 405
ramesh Avatar asked Jul 09 '14 11:07

ramesh


3 Answers

Insert this in your ui script.

tags$style(type="text/css",
         ".shiny-output-error { visibility: hidden; }",
         ".shiny-output-error:before { visibility: hidden; }"
)
like image 134
radhikesh93 Avatar answered Oct 17 '22 01:10

radhikesh93


You actually have two suppress functions via R that work differently for you:

suppressMessages() evaluates its expression in a context that ignores all ‘simple’ diagnostic messages." See ?suppressMessages.

  • suppressWarnings() evaluates its expression in a context that ignores all warnings. See ?suppressWarnings.

Examples:

f <- function(a) { a ; warning("This is a warning") ; message("This is a message not a warning")}

> f(1)
This is a message not a warning
Warning message:
In f(1) : This is a warning

> suppressWarnings(f(1))
This is a message not a warning

> suppressMessages(f(1))
Warning message:
In f(1) : This is a warning
like image 42
theforestecologist Avatar answered Oct 17 '22 01:10

theforestecologist


Wrapping suppressWarnings around your code should work. See ?suppressWarnings. You need to do something like:

atest <- function(n) {warning("a warning"); return(n+1)}
atest(1)
#[1] 2
#Warning message:
#In atest(2) : a warning

suppressWarnings(atest(1))
#[1] 2

But I guess that the better solution is to actually deal with the warning and not just ignore it.

like image 28
Anders Ellern Bilgrau Avatar answered Oct 17 '22 02:10

Anders Ellern Bilgrau