| toast | R Documentation |
Toast notifications are lightweight, temporary messages designed to mimic push notifications from mobile and desktop operating systems. They are built on Bootstrap 5's toast component.
bslib includes a complete example of toasts and their many configuration options:
shiny::runExample("toast", package = "bslib")
toast(
...,
header = NULL,
icon = NULL,
id = NULL,
type = NULL,
duration_s = 5,
position = "top-right",
closable = TRUE
)
toast_header(title, ..., icon = NULL, status = NULL)
... |
Body content of the toast. Can be a string, or any HTML elements. Named arguments will be treated as HTML attributes for the toast container. |
header |
Optional header content. Can be a string, or the result of
|
icon |
Optional icon element, for example from |
id |
Optional unique identifier for the toast. If |
type |
Optional semantic type. One of |
duration_s |
Numeric. Number of seconds after which the toast should
automatically hide. Use |
position |
String or character vector specifying where to position the toast container. Can be provided in several formats:
Valid vertical positions are |
closable |
Logical. Whether to include a close button. Defaults to
|
title |
Header text (required). |
status |
Optional status text that appears as small, muted text on the right side of the header. |
A bslib_toast object that can be passed to show_toast().
For toast_header(): a toast header object that can be used with the
header argument of toast().
toast(): Create a toast element.
toast_header(): Create a structured toast header with optional icon and
status indicator. Returns a data structure that can be passed to the
header argument of toast().
show_toast() to display a toast, hide_toast() to dismiss a
toast, and toast_header() to create structured headers.
Other Toast components:
show_toast()
library(shiny)
library(bslib)
ui <- page_fluid(
actionButton("show_simple", "Simple Toast"),
actionButton("show_header", "Toast with Header")
)
server <- function(input, output, session) {
observeEvent(input$show_simple, {
show_toast(
toast(
"Operation completed successfully!",
header = "Success",
type = "success"
)
)
})
observeEvent(input$show_header, {
show_toast(
toast(
"Your settings have been saved.",
header = toast_header(
title = "Settings Updated",
status = "just now"
),
type = "success"
)
)
})
}
shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.