Skip to content

email output of gt table using blastula has raw html included with formatted table (issue with version 0.9.0+) #1506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 tasks done
kristymazoo opened this issue Dec 8, 2023 · 7 comments · Fixed by #1520

Comments

@kristymazoo
Copy link

kristymazoo commented Dec 8, 2023

Prework

Description

When adding a gt table to email body via blastula, the output now shows raw html in addition to the table instead of just the formatted output. It was working fine in v0.8.0 but doesn't work from v0.9.0 and up.

Reproducible example

  • Post a minimal reproducible example so the maintainer can troubleshoot the problems you identify. A reproducible example is:
    • Runnable: post enough R code and data so any onlooker can create the error on their own computer.
    • Minimal: reduce runtime wherever possible and remove complicated details that are irrelevant to the issue at hand.
    • Readable: format your code according to the tidyverse style guide.
library(blastula)
library(stringr)
library(htmltools)
library(tidyverse)
library(gt)
#> 
#> Attaching package: 'gt'
#> The following object is masked from 'package:blastula':
#> 
#>     md

tbl <- gt::gt(mtcars %>% head(5)) %>% 
  gt::as_raw_html()
email_body <- md(
  c("Hello all!\n", 
    tbl, "\n",
    "Thank you.")
  )

(body <- compose_email(body = email_body))

Created on 2023-12-08 with reprex v2.0.2

using gt v0.9.0
image

Expected result

using gt v0.8.0
image

Session info

End the reproducible example with a call to sessionInfo() in the same session (e.g. reprex(session_info = TRUE)) and include the output.

> sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

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

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

other attached packages:
 [1] gt_0.9.0        lubridate_1.9.3 forcats_1.0.0   dplyr_1.1.3     purrr_1.0.2     readr_2.1.4     tidyr_1.3.0    
 [8] tibble_3.2.1    ggplot2_3.4.4   tidyverse_2.0.0 htmltools_0.5.7 stringr_1.5.0   blastula_0.3.4 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.11       compiler_4.2.2    pillar_1.9.0      tools_4.2.2       digest_0.6.33     timechange_0.2.0 
 [7] jsonlite_1.8.7    lifecycle_1.0.4   gtable_0.3.4      lattice_0.20-45   pkgconfig_2.0.3   png_0.1-8        
[13] rlang_1.1.2       Matrix_1.5-1      cli_3.6.1         rstudioapi_0.15.0 commonmark_1.9.0  curl_5.1.0       
[19] fastmap_1.1.1     xml2_1.3.5        withr_2.5.2       sass_0.4.7        hms_1.1.3         generics_0.1.3   
[25] vctrs_0.6.4       rappdirs_0.3.3    tidyselect_1.2.0  rprojroot_2.0.4   grid_4.2.2        juicyjuice_0.1.0 
[31] reticulate_1.34.0 glue_1.6.2        here_1.0.1        R6_2.5.1          fansi_1.0.5       tzdb_0.4.0       
[37] magrittr_2.0.3    scales_1.2.1      colorspace_2.1-0  V8_4.4.0          utf8_1.2.4        stringi_1.7.12   
[43] munsell_0.5.0    
@rich-iannone
Copy link
Member

Thanks for reporting this! This will be fixed shortly.

@Nova-Scotia
Copy link

I'm still experiencing this issue (or one very similar), using gt v 0.10.0.

sessionInfo()
R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.utf8  LC_CTYPE=English_Canada.utf8    LC_MONETARY=English_Canada.utf8
[4] LC_NUMERIC=C                    LC_TIME=English_Canada.utf8    

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

other attached packages:
 [1] gt_0.10.0       lubridate_1.9.2 forcats_1.0.0   dplyr_1.1.2     purrr_1.0.2     readr_2.1.4     tidyr_1.3.0    
 [8] tibble_3.2.1    ggplot2_3.4.3   tidyverse_2.0.0 htmltools_0.5.5 stringr_1.5.0   blastula_0.3.3 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.11       pillar_1.9.0      compiler_4.2.3    tools_4.2.3       digest_0.6.31     jsonlite_1.8.7   
 [7] timechange_0.2.0  lifecycle_1.0.3   gtable_0.3.4      pkgconfig_2.0.3   rlang_1.1.1       cli_3.6.1        
[13] rstudioapi_0.15.0 commonmark_1.9.0  curl_5.1.0        fastmap_1.1.1     xml2_1.3.5        withr_2.5.0      
[19] sass_0.4.6        generics_0.1.3    vctrs_0.6.3       hms_1.1.3         grid_4.2.3        tidyselect_1.2.0 
[25] juicyjuice_0.1.0  glue_1.6.2        R6_2.5.1          fansi_1.0.4       tzdb_0.4.0        magrittr_2.0.3   
[31] scales_1.2.1      colorspace_2.1-0  V8_4.3.0          utf8_1.2.3        stringi_1.7.12    munsell_0.5.0    

I copied and pasted the example code above:

library(blastula)
library(stringr)
library(htmltools)
library(tidyverse)
library(gt)


tbl <- gt::gt(mtcars %>% head(5)) %>% 
  gt::as_raw_html()
email_body <- md(
  c("Hello all!\n", 
    tbl, "\n",
    "Thank you.")
)

(body <- compose_email(body = email_body))

And my result shows a very wide preview... here's the left side (ha!):

image

and the middle (note the missing table headers):
image

@rich-iannone
Copy link
Member

Hi @Nova-Scotia this is fixed by updating gt to using the in-development version. Could you install that with

devtools::install_github("rstudio/gt")

and try the email generation again? We're going to submit gt to CRAN soon, so this problem should go away when using a CRAN version of gt.

@rich-iannone rich-iannone reopened this Jan 12, 2024
@github-project-automation github-project-automation bot moved this from Done to Backlog in R Markdown Team Projects Jan 12, 2024
@Nova-Scotia
Copy link

@rich-iannone thanks. That did the trick.

@rich-iannone
Copy link
Member

That’s great to hear!

@stevensmallberg
Copy link

I have encountered a variant of this issue in v0.10.1 when adding a header to a gt table. Fortunately, there appears to be a fairly simple workaround.

Here I adapt the reprex posted in this issue's original description:

library(blastula)
library(glue)
library(gt)
#> 
#> Attaching package: 'gt'
#> The following object is masked from 'package:blastula':
#> 
#>     md
library(stringr)

tbl <- 
  mtcars |> 
  head() |> 
  gt() |> 
  # Adding a header to the table produces the issue
  tab_header("Motor Trend cars") |> 
  as_raw_html()

email_body <- " Hello all! {tbl} Thank you."

email_body |> 
  glue() |> 
  # Removing whitespace resolves the issue
  # stringr::str_squish() |> 
  md() |> 
  compose_email()

Created on 2024-02-05 with reprex v2.1.0

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.1 (2023-06-16)
#>  os       macOS Sonoma 14.1
#>  system   x86_64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/Los_Angeles
#>  date     2024-02-05
#>  pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  blastula    * 0.3.4   2023-09-23 [1] CRAN (R 4.3.0)
#>  cli           3.6.2   2023-12-11 [1] CRAN (R 4.3.0)
#>  commonmark    1.9.1   2024-01-30 [1] CRAN (R 4.3.2)
#>  curl          5.2.0   2023-12-08 [1] CRAN (R 4.3.0)
#>  digest        0.6.34  2024-01-11 [1] CRAN (R 4.3.0)
#>  dplyr         1.1.4   2023-11-17 [1] CRAN (R 4.3.0)
#>  evaluate      0.23    2023-11-01 [1] CRAN (R 4.3.0)
#>  fansi         1.0.6   2023-12-08 [1] CRAN (R 4.3.0)
#>  fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.3.0)
#>  fs            1.6.3   2023-07-20 [1] CRAN (R 4.3.0)
#>  generics      0.1.3   2022-07-05 [1] CRAN (R 4.3.0)
#>  glue        * 1.7.0   2024-01-09 [1] CRAN (R 4.3.0)
#>  gt          * 0.10.1  2024-01-17 [1] CRAN (R 4.3.0)
#>  htmltools     0.5.7   2023-11-03 [1] CRAN (R 4.3.0)
#>  jsonlite      1.8.8   2023-12-04 [1] CRAN (R 4.3.0)
#>  juicyjuice    0.1.0   2022-11-10 [1] CRAN (R 4.3.0)
#>  knitr         1.45    2023-10-30 [1] CRAN (R 4.3.1)
#>  lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.3.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.3.0)
#>  pillar        1.9.0   2023-03-22 [1] CRAN (R 4.3.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.3.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.3.0)
#>  Rcpp          1.0.12  2024-01-09 [1] CRAN (R 4.3.0)
#>  reprex        2.1.0   2024-01-11 [1] CRAN (R 4.3.0)
#>  rlang         1.1.3   2024-01-10 [1] CRAN (R 4.3.0)
#>  rmarkdown     2.25    2023-09-18 [1] CRAN (R 4.3.0)
#>  rstudioapi    0.15.0  2023-07-07 [1] CRAN (R 4.3.0)
#>  sass          0.4.8   2023-12-06 [1] CRAN (R 4.3.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.3.0)
#>  stringi       1.8.3   2023-12-11 [1] CRAN (R 4.3.0)
#>  stringr     * 1.5.1   2023-11-14 [1] CRAN (R 4.3.0)
#>  tibble        3.2.1   2023-03-20 [1] CRAN (R 4.3.0)
#>  tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.3.0)
#>  utf8          1.2.4   2023-10-22 [1] CRAN (R 4.3.0)
#>  V8            4.4.1   2023-12-04 [1] CRAN (R 4.3.0)
#>  vctrs         0.6.5   2023-12-01 [1] CRAN (R 4.3.0)
#>  withr         3.0.0   2024-01-16 [1] CRAN (R 4.3.0)
#>  xfun          0.41    2023-11-01 [1] CRAN (R 4.3.0)
#>  xml2          1.3.6   2023-12-04 [1] CRAN (R 4.3.0)
#>  yaml          2.3.8   2023-12-11 [1] CRAN (R 4.3.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Thank you, Rich, for your work on this fantastic pair of packages.

@asadow
Copy link

asadow commented Mar 15, 2024

The header issue was affecting me as well. Thank you @stevensmallberg for the quick fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment