【问题标题】:R Shiny Picker Input search in named choice header and contentR Shiny Picker Input 搜索命名选择标题和内容
【发布时间】:2020-03-11 10:50:17
【问题描述】:

我正在尝试修改Shiny 中的搜索栏,例如我们可以在pickerInput 中键入内容或他的标题。

代码示例:

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)

这种方式是想在搜索栏中输入文本Choice 2Other 并获得第二个输入。但是对Other 的研究没有结果。

隐藏标题但可以搜索的答案可能会被接受。

任何帮助将不胜感激。

【问题讨论】:

    标签: r shiny bootstrap-select selectinput pickerinput


    【解决方案1】:

    如果您安装了 {shinyWidgets} 的开发版(v0.4.9.940,即将在 CRAN 上使用),您可以在 choicesOpt 中传递一个插槽 tokens 来声明一些用于实时搜索的关键字:

    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)
    

    【讨论】:

    • 非常感谢。伟大的添加和简单的解决方案!不幸的是,我必须在我的专业环境中使用当前版本。我会记住 CRAN 的下一个版本。
    • 现在在 CRAN 上 :)
    • 一个愉快的环境组合:)
    猜你喜欢
    • 2019-05-07
    • 2019-09-09
    • 2017-09-09
    • 1970-01-01
    • 2019-07-28
    • 2019-09-12
    • 2021-11-14
    • 1970-01-01
    • 2020-02-18
    相关资源
    最近更新 更多