Search code examples
rshinyshinywidgets

Change color of notification in R shiny


I am trying to use the funcion "showNotification" to display a green pop up.
The official documentation says, you can use the parameter 'type' to change the color.

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

Has anyone tried this before?
Is there any way to use the HTML/HEX codes?

UPDATE
I ended up re-coloring the single types of showNotifications like this:

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

Solution

  • You can add some style yourself:

    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"
          )
        })
      }
    )
    

    enter image description here