Repository navigation
Closed
Description
Hi, when building a large app with many inputs, I noticed a performance issue.
library(shiny)
library(bslib)
ui <- fluidPage(
theme = bs_theme(bootswatch = "slate"),
do.call("tagList", lapply(1:200, function(x) {
selectInput(paste0("id", x), "Another input", choices = LETTERS, selectize = TRUE)
}))
)
server <- function(input, output, session) {}
shinyApp(ui, server)
Profiling the app with
profvis::profvis(runApp('app.R'))
shows that bslib::bs_dependency() is called many times and causes the slowdown. Total time: 6580ms on my computer.
The time goes down to 1320ms if selectize = FALSE or if bslib is not used.
Related question: https://stackoverflow.com/q/67726350 (I didn't ask that question but I took its reprex)
sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.5.2
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] bslib_0.3.0 shiny_1.6.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.7 magrittr_2.0.1 xtable_1.8-4 R6_2.5.0
[5] rlang_0.4.11 fastmap_1.1.0 fansi_0.5.0 stringr_1.4.0
[9] tools_4.1.0 sessioninfo_1.1.1 utf8_1.2.2 cli_3.0.1
[13] withr_2.4.2 jquerylib_0.1.4 htmltools_0.5.2 ellipsis_0.3.2
[17] yaml_2.2.1 digest_0.6.27 tibble_3.1.3 lifecycle_1.0.0
[21] crayon_1.4.1 later_1.2.0 vctrs_0.3.8 profvis_0.3.7
[25] sass_0.4.0 htmlwidgets_1.5.3 promises_1.2.0.1 fs_1.5.0
[29] cachem_1.0.5 mime_0.11 stringi_1.7.3 pillar_1.6.2
[33] compiler_4.1.0 jsonlite_1.7.2 httpuv_1.6.1 renv_0.14.0
[37] pkgconfig_2.0.3
Metadata
Metadata
Assignees
Labels
No labels
Activity
wch commentedon Sep 17, 2021
This appears to be related to the presence of an html dependency. The same slowdown happens with
sliderInput, which attaches anhtmlDependencyobject to the HTML.For example, this shows about 6500 milliseconds of CPU time on my computer
If the
sliderInputis replaced with something that doesn't have anhtmlDependency, liketextInput, then it is fast (250ms):Similarly, if we keep the
sliderInput, but just remove thetheme=bs_theme(), then it is still fast (650ms):So the problem appears to be an interaction between bslib and having many html dependency objects.
Memoise calls to func() made via bs_dependency_defer() (more directly…
Memoise calls to func() made via bs_dependency_defer() (more directly…
github-actions commentedon Jul 24, 2023
This issue has been automatically locked. If you believe you have found a related problem, please open a new issue (with a reproducible example or feature request) and link to this issue.