简体   繁体   中英

R Shiny Picker Input search in named choice header and content

I am trying to modify a search bar in Shiny such as we can type either the content or his header in pickerInput .

Code example:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  pickerInput(
    inputId = "pick", label = "Selected", 
    choices = split(c("Choice 1" = "Value 1", "Choice 2" = "Value 2"), c("First", "Other")), 
    multiple = TRUE,
    options = list( `live-search` = TRUE)
  )
)

server <- function(input, output, session) {
}

shinyApp(ui, server)

This way is would like to type text Choice 2 or Other in search bar and get the second input. But research on Other gives no result.

An answer that hide the header but can search on it might be accepted.

Any help would be greatly appreciated.

If you install development version of {shinyWidgets} (v0.4.9.940, soon on CRAN), you can pass a slot tokens in choicesOpt to declare some keywords used in live search:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  pickerInput(
    inputId = "pick", label = "Selected", 
    choices = split(c("Choice 1" = "Value 1", "Choice 2" = "Value 2"), c("First", "Other")), 
    multiple = TRUE,
    options = list( `live-search` = TRUE),
    choicesOpt = list(
      tokens = c("first choice 1", "other choice 2")
    )
  )
)

server <- function(input, output, session) {
}

shinyApp(ui, server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM