I use pickerInput
function from the shinyWidgets
package in Shiny to have a dropdown menu. For example part of my ui.R
:
library(shiny)
library(data.table)
library(shinyWidgets)
.
.
#Rating
pickerInput(
inputId = "rate",
label = "Rating:",
choices = c(as.character(unique(datT2[order(rat.ord)]$Rating))),
selected = sort(unique(as.character(datT2$Rating ))),
options = list(`actions-box` = TRUE,
`selected-text-format` = paste0("count > ", length(unique(as.character(datT2$Rating )))-1) ,
`count-selected-text` = "Alle",liveSearch = TRUE,
liveSearchPlaceholder= TRUE),
multiple = T
)
before this function I applied just the normal function:
#Rating
selectInput("rate",
"Rating:",
choices = c("Alle",
sort(unique(as.character(datT2$Rating )))),
selected = "Alle",
multiple = TRUE)
In selectInput
function is possible to search based on typing but not possible to deselect the selected items just by click like in pickerInput
.
How can I have the search option based on typing letters in pickerInput
?
A bit of a late answer, but your option-naming is wrong. Change liveSearch
in live-search
and it will work.
options = list(`live-search`=TRUE)
EDIT
If you have shinyWidgets >= 4.4
you can also use the function pickerOptions
for setting the options. You can check all possible options by calling ?pickerOptions
or check this url.
An example with both methods:
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
pickerInput('picker 1', 'picker1', c(1,2,3,4,5), options=pickerOptions(liveSearch=T)),
pickerInput('picker 2', 'picker2', c(1,2,3,4,5), options = list(`live-search`=TRUE))
)
server <- function(input, output, session) {}
shinyApp(ui, server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With