0

See example:

shinyFunction <- function(){
  shinyApp(
    ui = basicPage(
      actionButton('print_message', "Print a message")
    ),
    
    server = function(input, output){
      observeEvent(input$print_message, {
        message("Here is a message")
      })
    } 
  ) 
}

The app prints a message to the console on-click.

How do I suppress this behavior?

Wrapping it with suppressMessages(shinyFunction()) does not work...

I don't want the console to print ANYTHING. How can I achieve this?

Many thanks in advance

geom_na
  • 258
  • 2
  • 10
  • 1
    You can wrap your code within `suppressWarnings`, `suppressMessages`. Alternatively you can follow [this](https://stackoverflow.com/questions/16194212/how-to-suppress-warnings-globally-in-an-r-script). – msr_003 May 13 '22 at 04:37

1 Answers1

0

There are many things that you can do here. As you rightly said, suppressWarnings() and suppressMessages() can be used in this case which will not print anything on the console. Alternatively, you can use the showNotification() function to show notifications in shiny app. https://shiny.rstudio.com/articles/notifications.html

shinyApp(
  ui = fluidPage(
    actionButton("show", "Show")
  ),
  server = function(input, output) {
    observeEvent(input$show, {
      showNotification("This is a notification.")
    })
  }
)

However, if you want to print attractive messages for the console, you can use the cli package in R.

cli::cli_alert_warning("This is a warning message")
# ! This is a warning message

cli::cli_alert_success("This is a success message")
# √ This is a success message

One more solution I would like to suggest here is to print the output or any messages in a log file and not on console.

Keep Coding!

Vishal Sharma
  • 289
  • 2
  • 10