Create sweetalerts in R with this function. For details on the arguments, see the SweetAlert demo.
1 2 3 4 5 6 7 8 | sweetalert(selector = NULL, event = "onclick", title = "", text = "",
type = NULL, allowOutsideClick = FALSE, showConfirmButton = TRUE,
showCancelButton = FALSE, closeOnConfirm = TRUE, closeOnCancel = TRUE,
confirmButtonText = "OK", confirmButtonColor = "#AEDEF4",
cancelButtonText = "Cancel", imageUrl = NULL, imageSize = NULL,
timer = NULL, customClass = "", html = FALSE, animation = TRUE,
allowEscapeKey = TRUE, inputType = "text", inputPlaceholder = "",
inputValue = "", evalFunction = NULL, width = 0, height = 0)
|
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 | ## Not run:
library(sweetalertR)
library(htmltools)
# do the first sweetalert example using a tagList
# and sweetalert with a selector
# This is the advisable way for most R users
browsable(tagList(
HTML('
<div class="showcase sweet">
<h4>Sweet Alert</h4>
<button>Show error message</button>
<h5>R Code:</h5>
<pre>
sweetalert(
selector = ".showcase.sweet button"
,title = "Oops..."
,text = "Something went wrong!"
,type = "error"
)
</pre>
</div>
')
,sweetalert(
selector = '.showcase.sweet button'
,title = "Oops..."
,text = "Something went wrong!"
,type = "error"
)
))
# do the first sweetalert example using a tagList
# but with sweetalert( selector = NULL )
# assuming someone knows HTML and JavaScript
browsable(tagList(
HTML('
<div class="showcase sweet">
<h4>Sweet Alert</h4>
<button onclick = "sweetAlert( \'Oops...\',\'Something went wrong!\',\'error\')">
Show error message
</button>
<h5>R Code:</h5>
<pre>
# no selector so sweetalert htmlwidget just used for dependencies
sweetalert()
</pre>
</div>
')
,sweetalert()
))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.