r - 使用闪亮的选择,避免对搜索结果进行排序
问题描述
在下面的可重现闪亮应用程序中,可搜索的选择字段按字符串的长度重新排序值。
如果我1
在搜索字段中键入,则 'Gears' 会出现在 'Cylinders' 上方,因为字符串更短。但是,我希望它们按原始顺序,即 11 高于 12 高于 13。
selectize repo中的一个线程建议添加类似的东西sortField: [{field: 'name', direction: 'asc'}]
,但我没有设法在闪亮的上下文中添加它。所以添加options = list(sortField = list(field = 'name', direction = 'asc'))
到selectizeInput()
没有效果。
library(shiny)
choices <- c(
"11 Cylinders" = "cyl",
"12 Transmission" = "am",
"13 Gears" = "gear"
)
shinyApp(
ui = fluidPage(
selectizeInput(
"variable",
"Variable:",
choices
)
),
server = function(input, output) {
}
)
解决方案
library(shiny)
# must have named vector for selectize.js to pick up on the injection
choices <- c(
"11 Cylinders" = "cyl",
"12 Transmission" = "am",
"13 Gears" = "gear"
)
# define JS to inject for options
##asceding order
sort_asc <- I("[{field: 'name', direction: 'asc'},{field: '$score'}]")
##decending order
sort_desc <- I("[{field: 'name', direction: 'desc'},{field: '$score'}]")
JS_opts <- list(create=TRUE,
labelField = 'name',
searchField = 'name',
sortField = sort_asc
)
shinyApp(
ui = fluidPage(
selectizeInput(
inputId = "variable",
label = "Variable:",
choices = choices,
options = JS_opts
)
),
server = function(input, output) {
}
)
推荐阅读
- excel - 为什么Excel中命名范围的行不是整数
- javascript - Antd Popover 在弹出框内单击时关闭
- kubernetes - 备份 Kubernetes 节点
- c# - 如果表单被阻止,是否有任何事件属性?
- arrays - 函数应该返回唯一的双精度,而不是数组
- typescript - 如何向 Typescript 商店内的 Quasar 项目添加通知
- python - 如何检查一个列表是否在python中的另一个列表中?
- angular - 如何将监听器添加到 ul li 列表?
- android - Azure 认知服务面向 Android - NoClassDefFoundError
- excel - excel,vlookup,错误信息,我们发现这个公式有问题