【问题标题】:Shiny selectizeInput set selected value with option闪亮的 selectizeInput 使用选项设置选定的值
【发布时间】:2020-07-27 16:42:30
【问题描述】:

我有一个自定义的selectizeInput,我使用 options 参数指定可用的选项(为了简单起见,示例中省略了自定义呈现和搜索)。现在我被困在设置选定值的简单任务上。根据文档,这应该可以使用 items 字段,但我正在努力寻找正确的设置方法。

library(shiny)
library(purrr)

choices <- purrr::transpose(list(x = letters[1:5],
                                 y = LETTERS[1:5]))

ui <- fluidPage(
  selectizeInput("select", 'Select', choices = "",
                 selected = "",
                 options = list(
                   valueField = 'x',
                   labelField = 'y',
                   items = choices[[1]],
                   options = choices
                 ))
)

shinyApp(ui, function(input, output, session) {})

【问题讨论】:

  • 这个的用例是什么?为什么不使用selected

标签: r shiny selectize.js


【解决方案1】:

那里可能有更好的选择,但这似乎可行。在options中添加以下内容:

onInitialize = I('function() { this.setValue("a"); }')

并在“6. Placeholder”下的shiny 库中查看selectize 示例:

https://shiny.rstudio.com/gallery/selectize-examples.html

ui <- fluidPage(
  selectizeInput("select", 'Select', choices = "",
                 selected = "",
                 options = list(
                   valueField = 'x',
                   labelField = 'y',
                   #items = choices[[1]],
                   onInitialize = I('function() { this.setValue("a"); }'),
                   options = choices
                 ))
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-18
    • 2016-03-19
    • 2021-12-13
    • 2019-03-20
    • 2019-01-24
    • 2018-12-22
    • 1970-01-01
    • 2014-07-06
    相关资源
    最近更新 更多