r - shinyWidgets updatePickerInput() 服务器端更新(类似于 updateSelectizeInput 函数)?
问题描述
有谁知道使用shinyWidgets::pickerInput()
大量选择但加快渲染速度的方法?(类似于服务器端选择 using updateSelectizeInput()
)
我最终想要做的是:拥有一个有大量选择(~1M)的shinyWidgets pickerInput()。
问题:加载这么多选择的应用程序需要很长时间。
我知道一种解决方法是使用shiny::selectizeInput()
UI 元素,因为有一种巧妙的方法来执行 server-side shiny::updateSelectInput()
,这使得初始 UI 元素的加载和随后使用一堆选项的更新运行得非常快(如所述在这篇文章中)。
但是,我真的很喜欢它提供的格式选项和灵活性shinyWidgets::pickerInput()
。
例子:
这可以快速工作并加载,但使用shiny::selectizeInput()
而不是shinyWidgets::pickerInput()
我想使用的 。
library(shiny)
ui = shiny::fluidPage(
shiny::uiOutput(outputId = "ui_output")
)
server = function(input, output) {
output$ui_output = shiny::renderUI({
shiny::selectizeInput(
inputId = "select",
label = "Select:",
choices = NULL
)
})
shiny::observe({
shiny::updateSelectizeInput(
inputId = "select",
choices = 1:1000000,
selected = 1,
server = TRUE
)
})
}
shiny::shinyApp(ui, server)
当尝试对 做同样的事情时shinyWidgets::pickerInput()
,我最初尝试将选项直接加载到 UI 中:
server = function(input, output) {
output$ui_output = shiny::renderUI({
shinyWidgets::pickerInput(
inputId = "select",
label = "Select:",
choices = 1:1000000
)
})
}
并且还尝试使用我在第一个示例中使用的相同逻辑,即最初使用 加载 UI 对象choices = NULL
,然后shiny::observe()
调用更新 UI 元素的选择(这可行,但速度很慢):
server = function(input, output) {
output$ui_output = shiny::renderUI({
shinyWidgets::pickerInput(
inputId = "select",
label = "Select:",
choices = NULL
)
})
shiny::observe({
shinyWidgets::updatePickerInput(
session = getDefaultReactiveDomain(),
inputId = "select",
choices = 1:1000000,
selected = 1
)
})
}
解决方案
推荐阅读
- sql - 使用 BigQuery 拆分字符串并使用拆分结果创建一个新列
- r - 将固定效应回归线添加到 ggplot
- c# - 将角色转向另一个方向左右移动不起作用
- excel - Powershell 实例化的 COM 对象随机使凭据失败
- python - Python3 / SQLAlchemy 1.4 / ORM / 创建表后引入新属性
- python - os listdir在使用jupyter notebook时找不到目录
- python - ValueError: 层 conv1d 的输入 0 与层不兼容:预期 ndim=3,发现 ndim=2。收到的完整形状:[64, 2000]
- javascript - 未捕获的 TypeError:knopkes.addEventListener 不是函数
- nlp - 一次从多个 PDF 文件中提取文本 Python
- python - ' '.join(context.args) 只接收字符串我怎样才能让它接收 int?