Skip to contents

Server-side function to show a top-centre message toast. Requires use_element() or el_page() in the UI to load the JS handler.

Usage

el_message(
  session,
  message,
  type = "info",
  duration = 3000,
  show_close = FALSE,
  center = FALSE
)

Arguments

session

Shiny session object.

message

Message text.

type

Message type: "info", "success", "warning", or "error". Default "info".

duration

Auto-close delay in milliseconds. 0 disables auto-close. Default 3000.

show_close

Whether to show the close button. Default FALSE.

center

Whether to centre the message text. Default FALSE.

Examples

if (interactive()) {
  library(shiny)
  library(shiny.element)
  ui <- el_page(
    el_button("btn", "Message", type = "primary")
  )
  server <- function(input, output, session) {
    observeEvent(input$btn, {
      el_message(session,
        message = "This is a message toast.",
        type    = "warning"
      )
    })
  }
  shinyApp(ui, server)
}