areNg aka areNg
areNg aka areNg

Reputation: 57

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;
                                                 }
                                                 '))),

Upvotes: 5

Views: 1292

Answers (1)

Pork Chop
Pork Chop

Reputation: 29407

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

Upvotes: 5

Related Questions