Open jangorecki opened 10 years ago
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,
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
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.
Selectize now enables duplicate entries. Can we have that feature in Shiny now
Just came accross this older issue. I‘m having the same problem atvthe moment. @wch or @jcheng5 any chance to reopen this?
It doesn't look to me like it is supported in selectize, fwiw.
I also didn't see this anyhere in Selectize, but I did see the feature request in a couple places (https://github.com/selectize/selectize.js/issues/129, https://github.com/selectize/selectize.js/issues/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
:
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)
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 ofc("field1","field2","field2")
. Currently AFAIK you cannot do that. Regards, Jan