r - 如何在使用 updateSelectizeInput 进行搜索时防止 selectInput 移动
问题描述
我有一个闪亮的大应用程序,其中有两个selectInput
,一个有两个选项,另一个用于updateSelectizeInput
获取server = TRUE
选项,因为要显示超过 36000 个元素,这会根据第一个中选择的内容而变化selectInput
。
它有效,但正如您从下面的 gif 中看到的那样,当我输入时,搜索框正在移动。我的猜测是它在服务器端搜索时移动。这可能是什么原因?我试图在一个简单的应用程序中重新创建问题,但是虽然我添加了应用程序的所有相关部分,但在可重现的示例中没有问题。
这是一个示例代码:
library(shiny)
library(shinyjs)
option_list1<-seq(1,36000,1)
option_list2<-seq(36000, 72000,1)
ui <- fluidPage(
useShinyjs(),
selectInput(
inputId = "scsource",
label = "Select source of scRNA-seq data",
choices = list(
"Carraro et al(2021) - Lung",
"Reyfman et al(2018) - Lung"
),
selected = NULL,
multiple = FALSE
),
uiOutput("scgeneinput")
)
server <- function(input, output, session) {
output$scgeneinput<-renderUI({
req(input$scsource)
selectInput(
"scgene",
"Select multiple genes",
multiple = TRUE,
choices = NULL
)
})
observeEvent(input$scsource, {
if (input$scsource == "Carraro et al(2021) - Lung"){
delay(500, updateSelectizeInput(session, "scgene", choices = option_list1, server = TRUE))
}
else if(input$scsource == "Reyfman et al(2018) - Lung"){
delay(500, updateSelectizeInput(session, "scgene", choices = option_list2, server = TRUE))
}
})
}
shinyApp(ui, server)
另外,我正在使用shinyjs::delay
函数,因为没有它,选项就看不到。这不会发生在小型可重现应用程序中。
任何帮助,将不胜感激。
解决方案
推荐阅读
- java - 为什么 FileReader 流从文本文件中读取 237、187、191?
- swagger - Swagger Swashbuckle 4.0 版本在 swagger 页面顶部引入了一个新的大白条
- grafana - 如何编辑因错误查询而一直冻结的 Grafana 仪表板
- android - 如何将 google play 和 testflight 中的 beta 用户转移到生产应用程序
- sql - 如何在 SQL Server 查询游标上绑定参数
- firebase - 部分匹配。文档至少包含搜索参数之一
- html - Woocommerce 使用 CSS 更改悬停时的产品图片
- c# - 为所有程序或单个 C# 创建数据访问类
- python - 如何计算变量之间的数字
- excel - 尝试使用通配符进行查找/替换