bslib icon indicating copy to clipboard operation
bslib copied to clipboard

bslib::bs_themer() is not compatible with inner fixedPage

Open CharlesBordet opened this issue 1 year ago • 1 comments

I upgraded to the latest version of bslib and can confirm that the problem persists.

Describe the problem

Using bslib::bs_themer() fails when the UI uses fixedPage() in its code.

Here is a minimal reproducible example:

ui <- fluidPage(
    title = "Test",
    theme = bslib::bs_theme(),
    fixedPage("test")
)

server <- function(input, output) {
    bslib::bs_themer()
}

shinyApp(ui, server)

And the error message:

Listening on http://127.0.0.1:5053
Browsing http://127.0.0.1:5053
Warning: Error in : `bslib::bs_themer()` requires `shiny::bootstrapLib()` to be present in the app's UI. Consider providing `bslib::bs_theme()` to the theme argument of the relevant page layout function (or, more generally, adding `bootstrapLib(bs_theme())` to the UI.
  42: stop
  41: bslib::bs_themer [/tmp/RtmpQ1Pvgh/R.INSTALL26981d69cd6522/bslib/R/bs-theme-preview.R#363]
  40: server [#2]
   3: runApp [/tmp/RtmpVRGFGf/R.INSTALL271ae265d30250/shiny/R/runapp.R#388]
   2: print.shiny.appobj [/tmp/RtmpVRGFGf/R.INSTALL271ae265d30250/shiny/R/shinyapp.R#565]
   1: <Anonymous>
Error : `bslib::bs_themer()` requires `shiny::bootstrapLib()` to be present in the app's UI. Consider providing `bslib::bs_theme()` to the theme argument of the relevant page layout function (or, more generally, adding `bootstrapLib(bs_theme())` to the UI.

The issue can be fixed by using bslib::page_fixed() instead of fixedPage(). However:

  • The error message is misleading
  • bslib appears compatible with using bslib::page_fixed() or fixedPage() interchangeably with no impact, so finding out the root of the issue is challenging

Some more tests/infos:

  • The bug appears with shiny::fixedPage() or shiny::fluidPage(). And can be fixed using bslib::page_fixed() or bslib::page_fluid().
  • The bug appears only when fixedPage() is used internally. As you can see in my example, I'm using a fluidPage in my initial call, and this one does not create the bug. It is only when used inside this function.
  • Using a fixedPage() inside a fluidPage() is relatively standard, typically to create a full-width header at the top of the page, and then a fixed-width container with the content of the page. Despite the misleading function naming, they don't create a page but a container, and we can have containers inside containers.

Session Info


> sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 12 (bookworm)

Matrix products: default BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.21.so; LAPACK version 3.11.0

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=fr_FR.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=fr_FR.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=fr_FR.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C

time zone: Europe/Paris tzcode source: system (glibc)

attached base packages: [1] stats graphics grDevices datasets utils methods base

other attached packages: [1] shiny_1.8.1.1

loaded via a namespace (and not attached): [1] crayon_1.5.2 vctrs_0.6.5 cli_3.6.2 rlang_1.1.3 renv_1.0.5
[6] promises_1.3.0 jsonlite_1.8.8 xtable_1.8-4 glue_1.7.0 htmltools_0.5.8.1 [11] httpuv_1.6.15 sass_0.4.9 fansi_1.0.6 jquerylib_0.1.4 tibble_3.2.1
[16] fastmap_1.1.1 yaml_2.3.8 lifecycle_1.0.4 memoise_2.0.1 compiler_4.3.3
[21] fs_1.6.3 pkgconfig_2.0.3 Rcpp_1.0.12 later_1.3.2 digest_0.6.35
[26] R6_2.5.1 utf8_1.2.4 pillar_1.9.0 magrittr_2.0.3 bslib_0.8.0.9000 [31] tools_4.3.3 mime_0.12 cachem_1.0.8

CharlesBordet avatar Dec 06 '24 07:12 CharlesBordet

Using a fixedPage() inside a fluidPage() is relatively standard, typically to create a full-width header at the top of the page, and then a fixed-width container with the content of the page.

You can (and should) achieve the same with:

ui <- fluidPage(
    title = "Test",
    theme = bslib::bs_theme(),
    div("test", class = "container")
)

Also, please consider using bslib::page_fluid() over fluidPage()

cpsievert avatar Dec 06 '24 15:12 cpsievert