我们的闪亮页面有多个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
在选择输入中:
#ui
selectizeInput("filter1","Please select from below list", choices = NULL, multiple = TRUE)
如何找到像我那样检测对象是否存在的条件exists("newData")
?我试过is.null(input$filter1$choises)
但这是不正确的。
感谢针对这种情况的任何建议。
提前致谢!