'Suppress messages in console when running shiny
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
Solution 1:[1]
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!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Vishal Sharma |