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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/notifications.R
\name{showNotification}
\alias{removeNotification}
\alias{showNotification}
\title{Show or remove a notification}
\usage{
showNotification(ui, action = NULL, duration = 5, closeButton = TRUE,
id = NULL, type = c("default", "message", "warning", "error"),
session = getDefaultReactiveDomain())
removeNotification(id = NULL, session = getDefaultReactiveDomain())
}
\arguments{
\item{ui}{Content of message.}
\item{action}{Message content that represents an action. For example, this
could be a link that the user can click on. This is separate from \code{ui}
so customized layouts can handle the main notification content separately
from action content.}
\item{duration}{Number of seconds to display the message before it
disappears. Use \code{NULL} to make the message not automatically
disappear.}
\item{closeButton}{If \code{TRUE}, display a button which will make the
notification disappear when clicked. If \code{FALSE} do not display.}
\item{id}{An ID string. This can be used to change the contents of an
existing message with \code{showNotification}, or to remove it with
\code{removeNotification}. If not provided, one will be generated
automatically. If an ID is provided and there does not currently exist a
notification with that ID, a new notification will be created with that ID.}
\item{type}{A string which controls the color of the notification. One of
"default" (gray), "message" (blue), "warning" (yellow), or "error" (red).}
\item{session}{Session object to send notification to.}
}
\value{
An ID for the notification.
}
\description{
These functions show and remove notifications in a Shiny application.
}
\examples{
## 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]
})
}
)
}
}
|