Description Usage Arguments Note Examples
createAlert creates an alert and inserts it in the DOM.
closeAlert closes an alert created via createAlert.
1 2 3 4 5 6 7 8 | createAlert(
id = NULL,
selector = NULL,
options,
session = shiny::getDefaultReactiveDomain()
)
closeAlert(id, session = shiny::getDefaultReactiveDomain())
|
id |
Anchor id. |
selector |
jQuery selector. Allow more customization for the anchor (nested tags). |
options |
List of options to pass to the alert. See below:
|
session |
Shiny session object. |
Unlike shinyBS, there is no need to specify an anchorId and an alertId. id refers to the anchorId, and the alertId is simply "anchorId-alert". On the server side, one can access the alert status by input$<id>. If TRUE, the alert has been created and is visible, if FALSE the alert has just been closed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | if (interactive()) {
library(shiny)
library(bs4Dash)
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
tooltip(
sliderInput("obs", "Observations:", 10, min = 1, max = 100),
placement = "right",
title = "Set me higher than 50!"
),
div(id = "myalert", style = "position: absolute; bottom: 0; right: 0;")
),
controlbar = dashboardControlbar(),
title = "Alerts",
),
server = function(input, output, session) {
observeEvent(input$obs, {
if (input$obs > 50) {
createAlert(
id = "myalert",
options = list(
title = "Alert",
closable = TRUE,
width = 12,
elevations = 4,
status = "primary",
content = "Alert content ..."
)
)
} else {
closeAlert(id = "myalert")
}
})
observe(print(input$myalert))
observeEvent(input$myalert, {
alertStatus <- if (input$myalert) "opened" else "closed"
toastColor <- if (input$myalert) "bg-lime" else "bg-fuchsia"
toast(
title = sprintf("Alert succesfully %s!", alertStatus),
options = list(
class = toastColor,
autohide = TRUE,
position = "topRight"
)
)
})
}
)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.