Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have the search option based on typing letters in pickerInput using shinyWidgets?

Tags:

r

shiny

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?

like image 806
maniA Avatar asked Dec 04 '18 09:12

maniA


1 Answers

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)
like image 149
Wilmar van Ommeren Avatar answered Nov 11 '22 16:11

Wilmar van Ommeren