Description Usage Arguments Value Examples
View source: R/notifications.R
These functions show and remove notifications in a Shiny application.
1 2 3 4 5 6 7 8 9 10 11 | showNotification(
ui,
action = NULL,
duration = 5,
closeButton = TRUE,
id = NULL,
type = c("default", "message", "warning", "error"),
session = getDefaultReactiveDomain()
)
removeNotification(id, session = getDefaultReactiveDomain())
|
ui |
Content of message. |
action |
Message content that represents an action. For example, this
could be a link that the user can click on. This is separate from |
duration |
Number of seconds to display the message before it
disappears. Use |
closeButton |
If |
id |
A unique identifier for the notification.
|
type |
A string which controls the color of the notification. One of "default" (gray), "message" (blue), "warning" (yellow), or "error" (red). |
session |
Session object to send notification to. |
An ID for the notification.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | ## Only run examples in interactive R sessions
if (interactive()) {
# Show a message when button is clicked
shinyApp(
ui = fluidPage(
actionButton("show", "Show")
),
server = function(input, output) {
observeEvent(input$show, {
showNotification("Message text",
action = a(href = "javascript:location.reload();", "Reload page")
)
})
}
)
# App with show and remove buttons
shinyApp(
ui = fluidPage(
actionButton("show", "Show"),
actionButton("remove", "Remove")
),
server = function(input, output) {
# A queue of notification IDs
ids <- character(0)
# A counter
n <- 0
observeEvent(input$show, {
# Save the ID for removal later
id <- showNotification(paste("Message", n), duration = NULL)
ids <<- c(ids, id)
n <<- n + 1
})
observeEvent(input$remove, {
if (length(ids) > 0)
removeNotification(ids[1])
ids <<- ids[-1]
})
}
)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.