首页 > 解决方案 > 在 R 中更改通知的颜色闪亮

问题描述

我正在尝试使用“showNotification”功能来显示绿色弹出窗口。
官方文档说,你可以使用参数'type'来改变颜色。

type    A string which controls the color of the notification. One of "default" (gray), "message" (blue), "warning" (yellow), or "error" (red).

有没有人试过这个?
有没有办法使用 HTML/HEX 代码?

更新
我最终重新着色了单一类型的 showNotifications,如下所示:

 tags$head(tags$style(HTML('
                                                 .shiny-notification-error {
                                                  background-color:#FF5757;
                                                  color:#000000;
                                                 }
                                                  .shiny-notification-message {
                                                  background-color:#B5E26F;
                                                  color:#000000;
                                                 }
                                                 '))),

标签: rshinyshinywidgets

解决方案


您可以自己添加一些样式:

library(shiny)
shinyApp(
  ui = fluidPage(
    tags$head(
      tags$style(
        HTML(".shiny-notification {background-color:#112446;}")
      )
    ),
    actionButton("show", "Show")
  ),
  server = function(input, output) {
    observeEvent(input$show, {
      showNotification("Message text",action = a(href = "javascript:location.reload();", "Reload page"),type = "warning"
      )
    })
  }
)

在此处输入图像描述


推荐阅读