toast: Toast

toastR Documentation

Toast

Description

Toast notifications.

Usage

toast(
  id,
  ...,
  class = "",
  position = c("top-right", "top-left", "bottom-right", "bottom-left")
)

Arguments

id

ID of toast, used to show/hide from server.

...

Content, generally toastHeader(), toastBody().

class

Any additional classes.

position

Position of the toast.

Examples

library(shiny)

ui <- fluidPage(
  theme = bslib::bs_theme(version = 5L),
  toast(
    "toast",
    toastHeader(
      strong(
        "Toast",
        class = "me-auto"
      )
    ),
    toastBody("The body of the toast!")
  ),
  h1("Hello"),
  actionButton("show", "Show toast"),
  actionButton("hide", "Hide toast")
)

server <- \(input, output, session){
  observeEvent(input$show, {
    toast_show("toast", auto_hide = FALSE)
  })

  observeEvent(input$hide, {
    toast_hide("toast")
  })
}

if(interactive())
 shinyApp(ui, server)


JohnCoene/bsutils documentation built on June 15, 2024, 3:21 a.m.