Skip to content

Commit

Permalink
inputSweetAlert(): added email and url
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Sep 5, 2021
1 parent 12f72b5 commit f89ce7c
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 152 deletions.
73 changes: 4 additions & 69 deletions R/sweetalert.R
Original file line number Diff line number Diff line change
Expand Up @@ -372,80 +372,15 @@ ask_confirmation <- function(inputId,
#' @seealso \code{\link{sendSweetAlert}}, \code{\link{confirmSweetAlert}},
#' \code{\link{closeSweetAlert}}.
#'
#' @examples
#' if (interactive()) {
#' library("shiny")
#' library("shinyWidgets")
#'
#'
#' ui <- fluidPage(
#' tags$h1("Input sweet alert"),
#' actionButton(inputId = "text", label = "Text Input"),
#' verbatimTextOutput(outputId = "text"),
#' actionButton(inputId = "password", label = "Password Input"),
#' verbatimTextOutput(outputId = "password"),
#' actionButton(inputId = "radio", label = "Radio Input"),
#' verbatimTextOutput(outputId = "radio"),
#' actionButton(inputId = "checkbox", label = "Checkbox Input"),
#' verbatimTextOutput(outputId = "checkbox"),
#' actionButton(inputId = "select", label = "Select Input"),
#' verbatimTextOutput(outputId = "select")
#' )
#' server <- function(input, output, session) {
#'
#' observeEvent(input$text, {
#' inputSweetAlert(
#' session = session, inputId = "mytext", input = "text",
#' title = "What's your name ?"
#' )
#' })
#' output$text <- renderPrint(input$mytext)
#'
#' observeEvent(input$password, {
#' inputSweetAlert(
#' session = session, inputId = "mypassword", input = "password",
#' title = "What's your password ?"
#' )
#' })
#' output$password <- renderPrint(input$mypassword)
#'
#' observeEvent(input$radio, {
#' inputSweetAlert(
#' session = session, inputId = "myradio", input = "radio",
#' inputOptions = c("Banana" , "Orange", "Apple"),
#' title = "What's your favorite fruit ?"
#' )
#' })
#' output$radio <- renderPrint(input$myradio)
#'
#' observeEvent(input$checkbox, {
#' inputSweetAlert(
#' session = session, inputId = "mycheckbox", input = "checkbox",
#' inputPlaceholder = "Yes I agree",
#' title = "Do you agree ?"
#' )
#' })
#' output$checkbox <- renderPrint(input$mycheckbox)
#'
#' observeEvent(input$select, {
#' inputSweetAlert(
#' session = session, inputId = "myselect", input = "select",
#' inputOptions = c("Banana" , "Orange", "Apple"),
#' title = "What's your favorite fruit ?"
#' )
#' })
#' output$select <- renderPrint(input$myselect)
#'
#' }
#'
#' shinyApp(ui = ui, server = server)
#' }
#' @example examples/sweetalert-input.R
inputSweetAlert <- function(session,
inputId,
title = NULL,
text = NULL,
type = NULL,
input = c("text", "password", "textarea", "radio", "checkbox", "select"),
input = c("text", "password", "textarea",
"radio", "checkbox", "select",
"email", "url"),
inputOptions = NULL,
inputPlaceholder = NULL,
btn_labels = "Ok",
Expand Down
54 changes: 37 additions & 17 deletions examples/sweetalert-input.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ library(shinyWidgets)

ui <- fluidPage(
tags$h1("Input sweet alert"),
actionButton(inputId = "text", label = "Text Input"),

actionButton("btn_text", "Text Input"),
verbatimTextOutput(outputId = "text"),
actionButton(inputId = "password", label = "Password Input"),

actionButton("btn_password", "Password Input"),
verbatimTextOutput(outputId = "password"),
actionButton(inputId = "radio", label = "Radio Input"),

actionButton("btn_radio", "Radio Input"),
verbatimTextOutput(outputId = "radio"),
actionButton(inputId = "checkbox", label = "Checkbox Input"),

actionButton("btn_checkbox", "Checkbox Input"),
verbatimTextOutput(outputId = "checkbox"),
actionButton(inputId = "select", label = "Select Input"),
verbatimTextOutput(outputId = "select")

actionButton("btn_select", "Select Input"),
verbatimTextOutput(outputId = "select"),

actionButton("btn_email", "Email Input"),
verbatimTextOutput(outputId = "email")
)
server <- function(input, output, session) {

observeEvent(input$text, {
observeEvent(input$btn_text, {
inputSweetAlert(
session = session,
inputId = "mytext",
"mytext",
input = "text",
title = "What's your name ?",
inputPlaceholder = "e.g.: Victor",
Expand All @@ -33,49 +41,61 @@ server <- function(input, output, session) {
})
output$text <- renderPrint(input$mytext)

observeEvent(input$password, {
observeEvent(input$btn_password, {
inputSweetAlert(
session = session,
inputId = "mypassword",
"mypassword",
input = "password",
title = "What's your password ?"
)
})
output$password <- renderPrint(input$mypassword)

observeEvent(input$radio, {
observeEvent(input$btn_radio, {
inputSweetAlert(
session = session,
inputId = "myradio",
"myradio",
input = "radio",
inputOptions = c("Banana" , "Orange", "Apple"),
title = "What's your favorite fruit ?"
)
})
output$radio <- renderPrint(input$myradio)

observeEvent(input$checkbox, {
observeEvent(input$btn_checkbox, {
inputSweetAlert(
session = session,
inputId = "mycheckbox",
"mycheckbox",
input = "checkbox",
inputPlaceholder = "Yes I agree",
title = "Do you agree ?"
)
})
output$checkbox <- renderPrint(input$mycheckbox)

observeEvent(input$select, {
observeEvent(input$btn_select, {
inputSweetAlert(
session = session,
inputId = "myselect",
"myselect",
input = "select",
inputOptions = c("Banana" , "Orange", "Apple"),
title = "What's your favorite fruit ?"
)
})
output$select <- renderPrint(input$myselect)

observeEvent(input$btn_email, {
inputSweetAlert(
session = session,
inputId = "myemail",
input = "email",
title = "What's your email ?",
validationMessage= "this does not look like a valid email!"
)
})
output$email <- renderPrint(input$myemail)

}

shinyApp(ui = ui, server = server)
if (interactive())
shinyApp(ui = ui, server = server)
167 changes: 101 additions & 66 deletions man/inputSweetAlert.Rd

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

0 comments on commit f89ce7c

Please sign in to comment.