Server-side function to show a desktop-corner notification popup.
Requires use_element() or el_page() in the UI to load the JS handler.
Usage
el_notification(
session = shiny::getDefaultReactiveDomain(),
message,
title = "",
type = "info",
duration = 4500,
position = "top-right",
show_close = TRUE,
offset = 0,
custom_class = NULL,
dangerously_use_html_string = FALSE,
id = NULL,
icon = NULL,
append_to = NULL,
z_index = NULL,
close_icon = NULL,
progress = NULL,
pause_on_hover = NULL
)Arguments
- session
Shiny session; the current one by default, as for
shiny::updateTextInput().- message
Notification body text, or a VNode built in the browser:
JS()code callingVue.h(), or a function returning one.- title
Notification title. Default
"".- type
Notification type:
"info","success","warning", or"error". Default"info".- duration
Auto-close delay in milliseconds.
0disables auto-close. Default4500.- position
Screen corner:
"top-right","top-left","bottom-right", or"bottom-left". Default"top-right".- show_close
Whether to show the close button. Default
TRUE.- offset
Distance from the corner edge in pixels. Default
0.- custom_class
Extra class name.
- dangerously_use_html_string
Whether
messageis inserted as HTML. Only passTRUEfor markup you control – it is not escaped.- id
Name for this notification, so
el_notification_close()can close it,input$<id>_closereports when it closes andinput$<id>_clickwhen it is clicked.- icon
Icon to show instead of the one
typeimplies, by name.- append_to
CSS selector of the element it is appended to. Default
<body>.- z_index
Its z-index, instead of the next one Element Plus hands out.
- close_icon
The close button's icon, by name.
- progress
Show a bar counting down
duration:TRUE, or a list of Element Plus's progress options.- pause_on_hover
Whether the countdown stops while the pointer is over it. Default
TRUE.
Examples
if (interactive()) {
library(shiny)
library(shiny.element)
ui <- el_page(
el_button("btn", "Notify", type = "primary")
)
server <- function(input, output, session) {
observeEvent(input$btn, {
el_notification(
session,
message = "Operation successful!",
title = "Success",
type = "success"
)
})
}
shinyApp(ui, server)
}