Skip to content

Commit

Permalink
example sweet alert with theme
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Nov 17, 2019
1 parent 68a73f6 commit b11b52f
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 5 deletions.
9 changes: 7 additions & 2 deletions R/sweetalert.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#'
#' @description
#' This function isn't necessary for \code{sendSweetAlert}, \code{confirmSweetAlert},
#' \code{inputSweetAlert}, but is still needed for \code{progressSweetAlert}.
#' \code{inputSweetAlert} (except if you want to use a theme other than the default one),
#' but is still needed for \code{progressSweetAlert}.
#'
#' @param theme Theme to modify alerts appearance.
#'
Expand All @@ -34,7 +35,11 @@
#' @importFrom htmltools attachDependencies htmlDependency singleton tagList tags
#'
#' @export
useSweetAlert <- function(theme = c("sweetalert2", "minimal", "dark", "bootstrap-4", "borderless")) {
#'
#' @example examples/useSweetAlert.R
useSweetAlert <- function(theme = c("sweetalert2", "minimal",
"dark", "bootstrap-4",
"borderless")) {
theme <- match.arg(theme)
tag_sa <- singleton(
tagList(
Expand Down
72 changes: 72 additions & 0 deletions examples/useSweetAlert.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
if (interactive()) {

library(shiny)
library(shinyWidgets)

ui <- fluidPage(

useSweetAlert("borderless"),

tags$h2("Sweet Alert examples"),
actionButton(
inputId = "success",
label = "Launch a success sweet alert",
icon = icon("check")
),
actionButton(
inputId = "error",
label = "Launch an error sweet alert",
icon = icon("remove")
),
actionButton(
inputId = "sw_html",
label = "Sweet alert with HTML",
icon = icon("thumbs-up")
)
)

server <- function(input, output, session) {

observeEvent(input$success, {
sendSweetAlert(
session = session,
title = "Success !!",
text = "All in order",
type = "success"
)
})

observeEvent(input$error, {
sendSweetAlert(
session = session,
title = "Error !!",
text = "It's broken...",
type = "error"
)
})

observeEvent(input$sw_html, {
sendSweetAlert(
session = session,
title = NULL,
text = tags$span(
tags$h3("With HTML tags",
style = "color: steelblue;"),
"In", tags$b("bold"), "and", tags$em("italic"),
tags$br(),
"and",
tags$br(),
"line",
tags$br(),
"breaks",
tags$br(),
"and an icon", icon("thumbs-up")
),
html = TRUE
)
})

}

shinyApp(ui, server)
}
82 changes: 79 additions & 3 deletions man/useSweetAlert.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b11b52f

Please sign in to comment.