【问题标题】:Shiny selectizeInput with value and label fields带有值和标签字段的闪亮 selectizeInput
【发布时间】:2019-06-28 14:19:15
【问题描述】:

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

【问题讨论】:

    标签: javascript r shiny selectize.js


    【解决方案1】:

    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) {}
    )
    

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2019-01-24
        • 2021-10-01
        • 2021-08-14
        • 2021-06-27
        • 1970-01-01
        • 2018-12-22
        • 1970-01-01
        • 1970-01-01
        • 2019-03-20
        相关资源
        最近更新 更多