rstudio / thematic

Theme ggplot2, lattice, and base graphics based on a few simple settings.
https://rstudio.github.io/thematic/
Other
244 stars 10 forks source link

Font size too small with bslib #121

Closed cbrnr closed 2 years ago

cbrnr commented 2 years ago

Describe the problem

I'm using bslib::bs_theme(bootswatch="flatly") together with thematic::thematic_shiny(font="auto") to make my figures look like the rest of the Shiny website. However, for some reason the labels in a figure are way too small initially. Once I resize the browser window a little bit, the figure adapts and shows the labels using the correct (larger) font size.

Here's a minimal Shiny app to reproduce this issue:

library(shiny)
library(bslib)
library(thematic)

thematic_shiny(font="auto")

x <- faithful[, 2]

ui <- fluidPage(
    theme=bs_theme(bootswatch="flatly"),

    titlePanel("Old Faithful Geyser Data"),

    sidebarLayout(
        sidebarPanel(
            sliderInput("bins", "Number of bins:", min=1, max=50, value=30)
        ),
        mainPanel(
           plotOutput("distPlot")
        )
    )
)

server <- function(input, output) {
    output$distPlot <- renderPlot({
        bins <- seq(min(x), max(x), length.out=input$bins + 1)
        hist(x, breaks=bins, col="darkgray", border="white")
    })
}

shinyApp(ui=ui, server=server)

Here's a screenshot of the website deployed to our own server (notice how the figure labels are very small):

1

And here's the same website after resizing the browser window a little (the figure labels are now larger as they should be):

2

Interestingly, running the app locally does not reproduce this issue. I couldn't reproduce the issue when deploying on shinyapps.io either, but I did run into the same problem with a bit more complex app.

I'm not even sure that this issue is related to thematic, so please let me know if this is some other package's problem (or even something I'm doing wrong).

Session Info


─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.1.3 (2022-03-10)
 os       macOS Big Sur 11.6.4
 system   x86_64, darwin17.0
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Vienna
 date     2022-03-16
 rstudio  2021.09.0+351 Ghost Orchid (desktop)
 pandoc   2.14.0.3 @ /Applications/RStudio.app/Contents/MacOS/pandoc/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 askpass       1.1     2019-01-13 [1] CRAN (R 4.1.0)
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.1.0)
 brio          1.1.3   2021-11-30 [1] CRAN (R 4.1.0)
 bslib       * 0.3.1   2021-10-06 [1] CRAN (R 4.1.0)
 cachem        1.0.6   2021-08-19 [1] CRAN (R 4.1.0)
 callr         3.7.0   2021-04-20 [1] CRAN (R 4.1.0)
 cli           3.2.0   2022-02-14 [1] CRAN (R 4.1.2)
 colorspace    2.0-3   2022-02-21 [1] CRAN (R 4.1.2)
 crayon        1.5.0   2022-02-14 [1] CRAN (R 4.1.2)
 curl          4.3.2   2021-06-23 [1] CRAN (R 4.1.0)
 DBI           1.1.2   2021-12-20 [1] CRAN (R 4.1.0)
 desc          1.4.1   2022-03-06 [1] CRAN (R 4.1.2)
 devtools      2.4.3   2021-11-30 [1] CRAN (R 4.1.0)
 digest        0.6.29  2021-12-01 [1] CRAN (R 4.1.0)
 dplyr         1.0.8   2022-02-08 [1] CRAN (R 4.1.2)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
 evaluate      0.15    2022-02-18 [1] CRAN (R 4.1.2)
 fansi         1.0.2   2022-01-14 [1] CRAN (R 4.1.2)
 farver        2.1.0   2021-02-28 [1] CRAN (R 4.1.0)
 fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.1.0)
 fs            1.5.2   2021-12-08 [1] CRAN (R 4.1.0)
 generics      0.1.2   2022-01-31 [1] CRAN (R 4.1.2)
 ggplot2       3.3.5   2021-06-25 [1] CRAN (R 4.1.0)
 glue          1.6.2   2022-02-24 [1] CRAN (R 4.1.2)
 gtable        0.3.0   2019-03-25 [1] CRAN (R 4.1.0)
 highr         0.9     2021-04-16 [1] CRAN (R 4.1.0)
 htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.1.0)
 httpuv        1.6.5   2022-01-05 [1] CRAN (R 4.1.2)
 jquerylib     0.1.4   2021-04-26 [1] CRAN (R 4.1.0)
 jsonlite      1.8.0   2022-02-22 [1] CRAN (R 4.1.2)
 knitr         1.37    2021-12-16 [1] CRAN (R 4.1.0)
 later         1.3.0   2021-08-18 [1] CRAN (R 4.1.0)
 lattice       0.20-45 2021-09-22 [1] CRAN (R 4.1.3)
 lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.1.0)
 magrittr      2.0.2   2022-01-26 [1] CRAN (R 4.1.2)
 memoise       2.0.1   2021-11-26 [1] CRAN (R 4.1.0)
 mime          0.12    2021-09-28 [1] CRAN (R 4.1.0)
 munsell       0.5.0   2018-06-12 [1] CRAN (R 4.1.0)
 openssl       2.0.0   2022-03-02 [1] CRAN (R 4.1.2)
 pillar        1.7.0   2022-02-01 [1] CRAN (R 4.1.2)
 pkgbuild      1.3.1   2021-12-20 [1] CRAN (R 4.1.0)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
 pkgload       1.2.4   2021-11-30 [1] CRAN (R 4.1.0)
 prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.1.0)
 processx      3.5.2   2021-04-30 [1] CRAN (R 4.1.0)
 promises      1.2.0.1 2021-02-11 [1] CRAN (R 4.1.0)
 ps            1.6.0   2021-02-28 [1] CRAN (R 4.1.0)
 purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.1.0)
 rappdirs      0.3.3   2021-01-31 [1] CRAN (R 4.1.0)
 Rcpp          1.0.8   2022-01-13 [1] CRAN (R 4.1.2)
 remotes       2.4.2   2021-11-30 [1] CRAN (R 4.1.0)
 rlang         1.0.2   2022-03-04 [1] CRAN (R 4.1.2)
 rmarkdown     2.12    2022-03-02 [1] CRAN (R 4.1.2)
 rprojroot     2.0.2   2020-11-15 [1] CRAN (R 4.1.0)
 rsconnect     0.8.25  2021-11-19 [1] CRAN (R 4.1.0)
 rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.0)
 sass          0.4.0   2021-05-12 [1] CRAN (R 4.1.0)
 scales        1.1.1   2020-05-11 [1] CRAN (R 4.1.0)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.1.0)
 shiny       * 1.7.1   2021-10-02 [1] CRAN (R 4.1.0)
 shinyjs     * 2.1.0   2021-12-23 [1] CRAN (R 4.1.0)
 showtext    * 0.9-5   2022-02-09 [1] CRAN (R 4.1.2)
 showtextdb  * 3.0     2020-06-04 [1] CRAN (R 4.1.0)
 sysfonts    * 0.8.5   2021-08-09 [1] CRAN (R 4.1.0)
 testthat      3.1.2   2022-01-20 [1] CRAN (R 4.1.2)
 thematic    * 0.1.2.1 2021-06-09 [1] CRAN (R 4.1.0)
 tibble      * 3.1.6   2021-11-07 [1] CRAN (R 4.1.0)
 tidyselect    1.1.2   2022-02-21 [1] CRAN (R 4.1.2)
 usethis       2.1.5   2021-12-09 [1] CRAN (R 4.1.0)
 utf8          1.2.2   2021-07-24 [1] CRAN (R 4.1.0)
 vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.0)
 withr         2.5.0   2022-03-03 [1] CRAN (R 4.1.2)
 xfun          0.30    2022-03-02 [1] CRAN (R 4.1.2)
 xtable        1.8-4   2019-04-21 [1] CRAN (R 4.1.0)
 yaml          2.3.5   2022-02-21 [1] CRAN (R 4.1.2)

 [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
cpsievert commented 2 years ago

Try using {ragg} by adding the following to the top of your app

library(ragg)
options(shiny.useragg = TRUE)
cbrnr commented 2 years ago

Thank you, that solved the issue! Maybe a small in the docs could be helpful? I know that the README mentions that "themes with custom fonts works best if you have {showtext} and/or {ragg} installed", but maybe this could be a stronger statement? I didn't even know that I was using custom fonts (and maybe I didn't, at least I never explicitly specified a particular font).