UpdateSelectizeInput的行为很奇怪

时间:2019-10-23 13:22:21

标签: r shiny

这可能与以下问题非常相似:

Shiny server-side updateSelectizeInput does not create selection list

我创建了一个MWE,以便您可以更好地监视问题。这个MWE原则基本上取自闪亮的https://shiny.rstudio.com/articles/selectize.html,但它没有产生预期的结果。

library(shiny)

# ui
ui <- fluidPage(
  fluidRow(
      selectizeInput('foo', label = NULL, choices = NULL, options = list(
        placeholder = 'Select something...')
    )
  )
)


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


  # update the render function for selectize
  updateSelectizeInput(session,
                       'foo',
                       choices = cbind(name = rownames(mtcars), mtcars),
                       server=T,
                       options = list(render = I(
                         '{
    option: function(item, escape) {
      return "<div><strong>" + escape(item.name) + "</strong> (" +
             "MPG: " + item.mpg +
             ", Transmission: " + item.am == 1 ? "automatic" : "manual" + ")"
    }
          }'))
  )

}

# Run the application 
shinyApp(ui = ui, server = server)

我真的不知道这里出了什么问题,并感谢任何提示。

1 个答案:

答案 0 :(得分:1)

在这里找到答案

https://groups.google.com/forum/#!topic/shiny-discuss/SCLzc8nKotM

我必须指定搜索,标签和valueField以便进行选择工作。