Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

inputSweetAlert

Launch an input text dialog


Description

Launch a popup with a text input

Usage

inputSweetAlert(
  session,
  inputId,
  title = NULL,
  text = NULL,
  type = NULL,
  input = c("text", "password", "textarea", "radio", "checkbox", "select"),
  inputOptions = NULL,
  inputPlaceholder = NULL,
  btn_labels = "Ok",
  btn_colors = NULL,
  reset_input = TRUE,
  ...
)

Arguments

session

The session object passed to function given to shinyServer.

inputId

The input slot that will be used to access the value. If in a Shiny module, it use same logic than inputs : use namespace in UI, not in server.

title

Title of the pop-up.

text

Text of the pop-up.

type

Type of the pop-up : "info", "success", "warning", "error" or "question".

input

Type of input, possible values are : "text", "password","textarea", "radio", "checkbox" or "select".

inputOptions

Options for the input. For "radio" and "select" it will be choices.

inputPlaceholder

Placeholder for the input, use it for "text" or "checkbox".

btn_labels

Label(s) for button(s).

btn_colors

Color(s) for button(s).

reset_input

Set the input value to NULL when alert is displayed.

...

Other arguments passed to JavaScript method.

Note

This function use the JavaScript sweetalert2 library, see the official documentation for more https://sweetalert2.github.io/.

See Also

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)
}

shinyWidgets

Custom Inputs Widgets for Shiny

v0.6.0
GPL-3
Authors
Victor Perrier [aut, cre, cph], Fanny Meyer [aut], David Granjon [aut], Ian Fellows [ctb] (Methods for mutating vertical tabs & updateMultiInput), Wil Davis [ctb] (numericRangeInput function), Spencer Matthews [ctb] (autoNumeric methods), JavaScript and CSS libraries authors [ctb, cph] (All authors are listed in LICENSE.md)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.