shiny + selectize.js:从本地源渲染自定义项目

shiny + selectize.js: render custom item from local source

我正在开发一个应用程序,用户可以在其中上传数据,然后 select 来自该数据的变量将被绘制在图表上。我希望变量的类型显示在 selector 中。

我正在使用示例 here and here (see "email contacts")。闪亮的 selectize 示例通过 ajax 获取数据,但我不知道如何调整它以适应用户上传的数据,这些数据作为 [=12= 存储在我的应用程序中] 目的。我还尝试使用 selectize 网站示例中的语法。我所有的努力都导致 select 或出现时没有任何类型的可见数据。

  # the code that creates the data I'm hoping to pass to the selector 
  stored_data$variable_selector <- data_frame(
    varlist = names(stored_data$data), 
    type = map_chr(names(stored_data$data), ~class(stored_data$data[[.x]]))
    ) %>% 
    purrr::transpose()

  # the code which currently renders an empty selector
  selectizeInput('variable', 'select a variable:', choices = '', options = list(
    valueField = 'varlist',
    labelField = 'type',
    searchField = 'varlist',
    options = stored_data$variable_types,
    create = FALSE,
    render = I("{
      option: function(item, escape) {
      return '<div>' +
           ' <em>' + escape(item.varlist) + '</em>' +
           ' (by ' + escape(item.type) + ')' +
    '</div>';
  }
}")))

我是否应该先将 variable_types 制作成 json 对象,然后再将其交给 selectize 中的渲染器?还有什么我想念的吗?

看来我的测试有误:下面呈现了一个 selectizeInput,其类型信息在下拉列表中可见。

library(shiny)
library(tidyverse)

iris_type <- data_frame(
  varlist = names(iris), 
  type = map_chr(names(iris), ~class(iris[[.x]]))
) %>% 
  purrr::transpose()

ui <- basicPage(


  # the code which currently renders an empty selector

    tagList(

    selectizeInput('variable', 'select a variable:', choices = '',
      options = list(
        valueField = 'varlist',
        labelField = 'varlist',
        searchField = c('varlist', 'type'),
        options = iris_type,
        create = FALSE,
        render = I(
          "{
            option: function(item, escape) {
            return '<div>' +
               ' <em>' + escape(item.varlist) + '</em>' +
               ' (type: ' + escape(item.type) + ')' +
               '</div>';
               }
             }"
            )
          )
        ),
    textOutput("out")
    )


)

server <- function(input, output, session) {
  output$out <- renderText(input$variable)
}

shinyApp(ui, server)