Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selectInput multiple, ADD: replace/duplicate argument #518

Open
jangorecki opened this issue Jun 18, 2014 · 7 comments
Open

selectInput multiple, ADD: replace/duplicate argument #518

jangorecki opened this issue Jun 18, 2014 · 7 comments

Comments

@jangorecki
Copy link

jangorecki commented Jun 18, 2014

Hi,
Would be nice to allow multiple selections of the same item in the selectInput.
Consider we have choices = c("field1","field2","field3","field4") and we want to pass from this input to shinyServer a vector of c("field1","field2","field2"). Currently AFAIK you cannot do that.
Regards,
Jan

@jangorecki jangorecki changed the title FR: selectInput multiple and replace/duplicate selectInput multiple, ADD: replace/duplicate argument Jun 18, 2014
@yihui yihui added this to the 0.10.1 milestone Jul 16, 2014
@yihui
Copy link
Member

yihui commented Jul 16, 2014

You can use the "vanilla" select input, i.e. selectInput(..., selectize = FALSE, multiple = TRUE), since selectize.js (@brianreavis) does not support duplicated values yet:

Whenever selectize.js supports this feature, we will try to catch up. Thanks!

@yihui yihui closed this as completed Jul 16, 2014
@jangorecki
Copy link
Author

Yihui,
could you please re-open issue?
I'm not able to achieve it using selectInput non selectize. You may not understand my question well, it is related to duplicates not in the choices vector but in the output vector. Please see example below

library(shiny)
runApp(list(
  ui = bootstrapPage( 
    sidebarPanel(
      selectInput("select1", "Select1:", c("A", "B", "C"), selectize = FALSE, multiple = TRUE)
    ),
    mainPanel(
      verbatimTextOutput("val")
      )
  ),
  server = function(input, output) {
    output$val <- renderPrint(input$select1)
  }
))

I would like to print: "A" "B" "B" which means no duplicates in choices arg but still duplicates on the selection/results.
Regards

@yihui
Copy link
Member

yihui commented Jul 16, 2014

I see. I do not think that is possible unless you provide A, B, B, C as the choices. This comes from the limitation of the web browser/standard, and we cannot do much about it in shiny. Sorry.

@debsush
Copy link

debsush commented May 3, 2016

Selectize now enables duplicate entries. Can we have that feature in Shiny now

@fabiangehring
Copy link

Just came accross this older issue. I‘m having the same problem atvthe moment. @wch or @jcheng5 any chance to reopen this?

@wch wch reopened this Feb 22, 2018
@jcheng5
Copy link
Member

jcheng5 commented Feb 5, 2019

It doesn't look to me like it is supported in selectize, fwiw.

@alandipert
Copy link
Contributor

I also didn't see this anyhere in Selectize, but I did see the feature request in a couple places (selectize/selectize.js#129, selectize/selectize.js#1371)

@debsush do you remember where you saw that it was supported by any chance?

Anyway, I offer the following workaround, which relies on renderUI:

ezgif-5-5aa6bc79f816

library(shiny)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      uiOutput("selectContainer")
    ),
    mainPanel(
      verbatimTextOutput("val"),
      actionButton("reset", "Reset")
    )
  )
)

server <- function(input, output, session) {
  choices <- c("A", "B", "C")
  chosen <- reactiveVal(c())
  observeEvent(input$reset, chosen(c()))
  output$selectContainer <- renderUI({
    # Take a dependency on chosen to re-render when an option is selected.
    chosen()
    selectInput( "select1", "Select1:", choices, selectize = TRUE, multiple = TRUE)
  })
  observeEvent(input$select1, {
    chosen(c(chosen(), input$select1))
  })
  output$val <- renderPrint(chosen())
}

shinyApp(ui, server)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants