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

"Error: fig.showtext code chunk option must be TRUE" when using thematic with font=auto #113

Closed cboettig closed 2 years ago

cboettig commented 2 years ago

The Rmd below generates a dashboard with that prints the error:

"Error: fig.showtext code chunk option must be TRUE"

on the dashboard display. The error is not suppressed by attempting to set chunk code options error=FALSE, (nor is it avoided by doing what it says and setting fig.showtext=TRUE). The error appears with static plots (base R and ggplot), but is not displayed on HTML-widget output.

The error is a result of the option font="auto" in thematic_rmd(). Avoiding that is a perfectly good solution, but not an obvious one -- perhaps this issue could at least be documented? (hence my opening this issue at least so google might have some search results for this. :-) ).

The fact that an error gets printed on the final output when knitr is obviously set to not show error messages suggests some other minor deeper issue. Ideally I would think flexdashboard and thematic would play nicely together with regards to automatic theming of font choices, (which I still find mind-boggling magic! the auto-theming with bslib and thematic is just :magic_wand: :exploding_head: !)

---
title: "Test"
output:
  flexdashboard::flex_dashboard:
    theme: 
      version: 4
      bootswatch: lux
---

```{r setup, include=FALSE}
library(flexdashboard)
library(thematic)
thematic::thematic_rmd(font = "auto")
```

# Tab

### Chart 1

```{r}
plot(pressure)
```
cpsievert commented 2 years ago

Strange, I can't seem to replicate the error, does re-rmarkdown::render()-ing from a fresh R session fix it?

If you can reliably reproducible, please include your session::session_info() and also the steps taken to render the document.

cboettig commented 2 years ago

Thanks for taking a look. Here's my sessionInfo()

R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so

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

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

other attached packages:
[1] thematic_0.1.2.1         ggplot2_3.3.5            flexdashboard_0.5.2.9000

loaded via a namespace (and not attached):
 [1] bslib_0.3.1      compiler_4.1.0   pillar_1.6.3     jquerylib_0.1.4  tools_4.1.0      digest_0.6.28    lattice_0.20-45 
 [8] jsonlite_1.7.2   evaluate_0.14    lifecycle_1.0.1  tibble_3.1.5     gtable_0.3.0     pkgconfig_2.0.3  rlang_0.4.11    
[15] DBI_1.1.1        rstudioapi_0.13  yaml_2.2.1       xfun_0.26        fastmap_1.1.0    withr_2.4.2      dplyr_1.0.7     
[22] knitr_1.36       generics_0.1.0   sass_0.4.0.9000  vctrs_0.3.8      tidyselect_1.1.1 grid_4.1.0       glue_1.4.2      
[29] R6_2.5.1         fansi_0.5.0      rmarkdown_2.11   purrr_0.3.4      magrittr_2.0.1   scales_1.1.1     htmltools_0.5.2 
[36] ellipsis_0.3.2   assertthat_0.2.1 colorspace_2.0-2 renv_0.14.0      utf8_1.2.2       munsell_0.5.0    crayon_1.4.1

I get the error msg showed on the output html (attached) with the knit button, which I think runs in a fresh session dashboard-debug.html.txt

cpsievert commented 2 years ago

Weird, I still can't reproduce, do you have {showtext} installed (if not install and try again)?

Another possible workaround would be to install {ragg} and add knitr::opts_chunk$set(dev = "ragg_png") to the setup chunk

cboettig commented 2 years ago

Nice -- didn't have {showtext} installed. installed that and the issue is resolved! :tada: