我們閃亮的頁面有多個selectizeInput
控件,其中一些在其下拉框中有長列表。因此,初始加載時間非常長,因爲它需要爲所有selectizeInput
控件預填充下拉框。R Shiny - 使用updateSelectizeInput優化頁面加載時間
編輯:請參閱下面的示例顯示如何加載長列表影響頁面加載時間。請複製下面的代碼並直接運行以查看加載過程。
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)
所以我想用戶點擊特定的複選框像see more filters
後更新這些selectizeInput
。但是,我不知道如何檢測它是否已經加載了列表。
爲了更清楚地解釋這一點,請參閱下面的解決方案來加載多個數據文件。
#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")
}
但是,如果它是更新selectizeInput choises
:
#ui
selectizeInput("filter1","Please select from below list", choices = NULL, multiple = TRUE)
如何找到一個條件像我一樣用於檢測是否對象exsits exists("newData")
?我試過is.null(input$filter1$choises)
但它不正確。
感謝有關此情況的任何建議。
提前致謝!
你能發表一個[可重現的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) - 即編輯您的問題與示例數據和一個完整的'shinydashboard'結構,有人可以用來幫助回答你的問題 – SymbolixAU
它不一定是你的整個代碼,只是一個最小的例子來重新創建你的問題 – SymbolixAU
@Symbolix感謝您的提醒。我用一個例子更新了我的問題。 –