toast | R Documentation |
Send notifications to the user. Create notification elements, toasts, with
the toast()
function. Display toasts with showToast()
and remove all
active toasts with closeToast()
.
toast(header, ...)
showToast(
toast,
duration = 4,
action = NULL,
session = getDefaultReactiveDomain()
)
closeToast(session = getDefaultReactiveDomain())
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.