| show_toast | R Documentation |
Displays a toast notification in a Shiny application.
show_toast(toast, ..., session = shiny::getDefaultReactiveDomain())
hide_toast(id, ..., session = shiny::getDefaultReactiveDomain())
toast |
A |
... |
Reserved for future extensions (currently ignored). |
session |
Shiny session object. |
id |
String with the toast ID returned by |
show_toast() Invisibly returns the toast ID (string) that can be
used with hide_toast().
show_toast(): Show a toast notification.
hide_toast(): Hide a toast notification by ID.
Other Toast components:
toast()
library(shiny)
library(bslib)
ui <- page_fluid(
actionButton("show_persistent", "Show Persistent Toast"),
actionButton("hide_persistent", "Hide Toast")
)
server <- function(input, output, session) {
toast_id <- reactiveVal(NULL)
observeEvent(input$show_persistent, {
id <- show_toast(
toast(
body = "This toast won't disappear automatically.",
autohide = FALSE
)
)
toast_id(id)
})
observeEvent(input$hide_persistent, {
req(toast_id())
hide_toast(toast_id())
toast_id(NULL)
})
}
shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.