Suppress warning message in console R shiny

We have developed a brilliant app. He showed some warning messages, we never bothered him, because the application is working fine. But we cannot distribute the application with a warning message appearing on the console. Now my question is: how to suppress a warning message in the R console when a brilliant application is running.

+4
source share
3 answers

Paste this into your ui script.

tags$style(type="text/css",
         ".shiny-output-error { visibility: hidden; }",
         ".shiny-output-error:before { visibility: hidden; }"
)
+7
source

In fact, you have two suppression functions through R that work differently for you:

suppressMessages() , " ". . ?suppressMessages.

  • suppressWarnings() , . . ?suppressWarnings.

:

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
+3

Wrapping suppressWarningsaround 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 think the best solution is to actually deal with the warning, and not just ignore it.

+1
source

Source: https://habr.com/ru/post/1547730/


All Articles