带有值和标签字段的闪亮 selectizeInput

Shiny selectizeInput with value and label fields

我想在 shiny 中自定义一个 selectizeInput,类似于 https://selectize.github.io/selectize.js/ 中的示例。值和标签应该不同,并且应该可以 select 多于 1 个条目并添加新条目(使用 create = TRUE 选项)。我已尝试使用 shinyWidgets 中的 selectizeInputpickerInput,但无法正常工作。

您可以在这里查看一些示例:shiny selectize examples

大部分高级选项都是通过选项设置的。这里是一个没有颜色的最小示例:

ui <- fluidPage(
  selectizeInput('myInput',
                 label='Select',
                 choices=c('first choice' = 'c1'),
                 multiple = TRUE,
                 options = list(create = TRUE))  
)

选项 render 允许设置 HTML 中的项目。这是一个例子:

library(shiny)

itemValues <- c("foo", "bar")
itemNames <- sprintf("<span style='background-color:springgreen'>%s</span>",
                     itemValues)
items <- setNames(itemValues, itemNames)

shinyApp(

  ui = fluidPage(
    selectizeInput("id", "Label", choices = items, 
                   options = list(render = I("
  {
    item: function(item, escape) { return '<div>' + item.label + '</div>'; },
    option: function(item, escape) { return '<div>' + item.label + '</div>'; }
  }")))
  ),

  server = function(input, output) {}
)