Description Usage Arguments Showing notifications Reacting to notifications See Also Examples
Send notifications to the user. Create notification elements, toasts, with
the toast()
function. Display toasts with showToast()
and remove all
active toasts with closeToast()
.
1 2 3 4 5 6 7 8 9 10 |
header |
A character string or tag element specifying a header for the
toast, defaults to |
... |
Any number of character strings or tag elements to include in the body of the toast. Any number of named arguments passed as HTML attributes to the parent element. |
toast |
A toast element, typically built with |
duration |
A positive integer or |
action |
A character string specifying a reactive id. If specified, the
hiding or closing of the toast will set the reactive id |
session |
A reactive context, defaults to |
ui <- container( buttonInput( id = "show", label = "Show notification" ) %>% margin(3) ) server <- function(input, output) { observeEvent(input$show, { showToast( toast( list( span("Notification") %>% margin(right = "4"), span(strftime(Sys.time(), "%H:%M")) %>% margin(right = 1) ), "This is notification ", input$show ) %>% margin(right = 2, top = 2) ) }) } shinyApp(ui, server)
When a notification is not automatically closed you may want to know when the notification is manually closed.
ui <- container( buttonInput( id = "show", label = "Show notification" ) %>% margin(3) ) server <- function(input, output) { observeEvent(input$show, { showToast( action = "undo", duration = NULL, toast( tags$strong("Close") %>% margin(right = "auto"), "When closing this notification, see the console" ) %>% margin(right = 2, top = 2) ) }) observeEvent(input$undo, { print("The notification was closed") }) } shinyApp(ui, server)
Other components:
alert()
,
badge()
,
blockquote()
,
card()
,
collapsePane()
,
d1()
,
dropdown()
,
img()
,
jumbotron()
,
modal()
,
navContent()
,
popover()
,
pre()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ### A simple toast
# The `"fade"` and `"show"` classes have been added for the sake of
# these examples.
toast(
class = "fade show",
header = div("Header") %>%
margin(right = "auto"),
"Hello, world!"
)
### Styling pieces of a toast
toast(
class = "fade show",
list(
div("Notification") %>%
font(weight = "bold") %>%
margin(right = "auto"),
tags$small("1 min ago")
),
"Hello, world!"
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.