shinyWidgets icon indicating copy to clipboard operation
shinyWidgets copied to clipboard

Reversed logic for named-list input in inputSweetAlert in "select"-mode

Open splendiduser opened this issue 1 year ago • 0 comments

I use named lists to make pickerInput or virtualSelectInput show different names for selectable items than what is output after selection. I noticed that inputSweetAlert reverses what is being used for the displayed items and the selected options. Modifying the example given with inputSweetAlert to compare the two input methods using the same named list:

library(shiny)
library(shinyWidgets)
choices <- c(Banana = "item1" , Orange = "item2", Apple = "item3")

ui <- fluidPage(
  tags$h1("Input sweet alert"),
  virtualSelectInput(
    "virtualselect",
    label = "test",
    choices = choices
  ),
  verbatimTextOutput(outputId = "virtualselect_output"),
  actionButton("btn_select", "Select Input"),
  verbatimTextOutput(outputId = "sweetalert_output")
)
server <- function(input, output, session) {
  
  observeEvent(input$btn_select, {
    inputSweetAlert(
      session = session,
      "myselect",
      input = "select",
      inputOptions = choices,
      title = "What's your favorite fruit ?"
    )
  })
  output$sweetalert_output <- renderPrint(input$myselect)
  
  output$virtualselect_output <- renderPrint(input$virtualselect)
}

shinyApp(ui = ui, server = server)

splendiduser avatar Mar 14 '24 10:03 splendiduser