我们闪亮的页面有多个selectizeInput控件,其中一些控件的下拉框中有很长的列表。因此,初始加载时间非常长,因为它需要为所有selectizeInput控件预先填充下拉框。
编辑:请参阅下面的示例,显示加载长列表如何影响页面加载时间。请复制以下代码并直接运行以查看加载过程。
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(
selectizeInput("a","filter 1",choices = sample(1:100000, 10000),multiple = T),
selectizeInput("b","filter 2",choices = sample(1:100000, 10000),multiple = T),
selectizeInput("c","filter 3",choices = sample(1:100000, 10000),multiple = T),
selectizeInput("d","filter 4",choices = sample(1:100000, 10000),multiple = T),
selectizeInput("e","filter 5",choices = sample(1:100000, 10000),multiple = T),
selectizeInput("f","filter 6",choices = sample(1:100000, 10000),multiple = T)
),
dashboardBody()
)
server <- function(input, output) {
}
shinyApp(ui, server)因此,我正在考虑在用户单击某些复选框(如selectizeInput )后更新这些see more filters。但是,我不知道如何检测它是否已经加载了列表。
要更清楚地解释这一点,请参见以下加载多个数据文件的解决方案。
#ui
checkboxInput("loadData", "load more data?", value = FALSE)
#server
#below runs only if checkbox is checked and it hasn't loaded 'newData' yet
#So after it loads, it will not load again 'newData'
if((input$loadData)&(!exists("newData"))){
newData<<- readRDS("dataSample.rds")
}但是,如果要更新choises中的selectizeInput:
#ui
selectizeInput("filter1","Please select from below list", choices = NULL, multiple = TRUE)如何找到像我所做的那样检测对象是否存在exists("newData")的条件?我试过is.null(input$filter1$choises),但它不正确。
感谢你对这种情况的任何建议。
提前感谢!
发布于 2016-03-02 00:22:08
最后,我从RStudio上的帖子中找到了解决方案。http://shiny.rstudio.com/articles/selectize.html
# in ui.R
selectizeInput('foo', choices = NULL, ...)
# in server.R
shinyServer(function(input, output, session) {
updateSelectizeInput(session, 'foo', choices = data, server = TRUE)
})当我们键入输入框时,selectize将开始搜索与我们输入的字符串部分匹配的选项。当所有可能的选项都写在HTML页面上时,可以在客户端完成搜索(默认行为)。这也可以在服务器端完成,使用R来匹配字符串并返回结果。当选择数量非常多时,这一点尤其有用。例如,当选择输入有10万个选项时,一次将它们全部写入页面会很慢,但是我们可以从空选择输入开始,只获取我们可能需要的选项,这可能会更快。我们将在下面介绍这两种类型的选择输入。
https://stackoverflow.com/questions/35664657
复制相似问题