dreamRs / shinyWidgets

shinyWidgets : Extend widgets available in shiny
https://dreamrs.github.io/shinyWidgets/
GNU General Public License v3.0
834 stars 153 forks source link

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

Open splendiduser opened 8 months ago

splendiduser commented 8 months ago

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)