警告:使用服务器端 selectize 可以大幅提高 RShiny 的性能

Can*_*ice 7 performance r shiny selectize.js

在 RShiny 应用程序中,我收到警告消息Warning message: The select input "the_input_id" contains a large number of options; consider using server-side selectize for massively improved performance. See the Details section of the ?selectizeInput help topic.

我有一个长度 == 3000 的命名向量名单,用于下拉选项。我尝试了以下两种方法来消除此警告:

用户界面

selectizeInput(
  inputId = 'the_input_id', label = 'Player 1 Search:', choices = namelist, selected = NULL,
  options = list(placeholder = 'Please select an option below', onInitialize = I('function() { this.setValue(""); }'))
)

uiOutput(outputId = 'this_id')
Run Code Online (Sandbox Code Playgroud)

服务器

updateSelectizeInput(session = session, inputId = 'the_input_id', label = 'Player 1 Search:', choices = namelist, server = TRUE,
                    options = list(placeholder = 'Please select an option below', onInitialize = I('function() { this.setValue(""); }')),
                           selected = ""
                           )

output$this_id<-renderUI ({
    selectizeInput(inputId = 'this_id', "Player 2 Search:", namelist,
                   options = list(
                     placeholder = 'Please select an option below',
                     onInitialize = I('function() { this.setValue(""); }')
                   ))
})
Run Code Online (Sandbox Code Playgroud)

the_input_id的方法是在 UI 中使用 selectizeInput() ,在服务器中使用 updateSelectizeInput() (我认为这是服务器端 selectize 的正确方法)。this_id的方法是在 UI 中使用 uiOutput(),在服务器上使用 renderUI + selectizeInput。这两种方法都会给出与我上面发布的相同的警告消息。我怎样才能解决这个问题/摆脱这个警告消息。

nei*_*fws 5

我认为问题在于您仍在使用 .UI 中生成选项列表choices = namelist

尝试使用choices = NULL替代。

要使其正常工作,请按照本指南“服务器端选择”部分中的示例进行操作。