简体   繁体   English

运行闪亮时抑制控制台中的消息

[英]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...suppressMessages(shinyFunction())包装它不起作用......

I don't want the console to print ANYTHING.我不希望控制台打印任何内容。 How can I achieve this?我怎样才能做到这一点?

Many thanks in advance提前谢谢了

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.正如您所说的那样,在这种情况下可以使用suppressWarnings()suppressMessages() ,它们不会在控制台上打印任何内容。 Alternatively, you can use the showNotification() function to show notifications in shiny app.或者,您可以使用showNotification()函数在闪亮的应用程序中显示通知。 https://shiny.rstudio.com/articles/notifications.html 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.但是,如果您想为控制台打印有吸引力的消息,您可以使用 R 中的cli包。

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!继续编码!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM