jthomasmock / gtExtras

A Collection of Helper Functions for the gt Package.
https://jthomasmock.github.io/gtExtras/
Other
195 stars 27 forks source link

`gt_fa_column` doesn't give an icon but some list text #114

Closed Cattiva closed 9 months ago

Cattiva commented 9 months ago

Prework

Description

The function gt_fa_column outputs some R code as text instead of the desired icon. I'm using the function once per quarter and today I experienced this strange behavior. I'm running R on Ubuntu for WSL, but the problem stays on Windows.

Reproducible example

Consider the following example:

tibble::tibble(
  fa_icon = "circle-check"
) |>
gt::gt() |>
gtExtras::gt_fa_column(
  fa_icon
)

This yields the following table: image

Running the example from the manual page leads to the same bug. However, the call to the fontawesome::fa() function seems to work just fine:

my_fa <- list(
  fontawesome::fa(
    "circle-check", 
    fill = "darkgreen", 
    height = "20px", 
    a11y = "sem") |> 
  gt::html()
  )

Converts it to

<svg aria-label="Circle Check" role="img" viewBox="0 0 512 512" style="height:20px;width:20px;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:darkgreen;overflow:visible;position:relative;"><title>Circle Check</title><path d="M256 48a208 208 0 1 1 0 416 208 208 0 1 1 0-416zm0 464A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM369 209c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-111 111-47-47c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9l64 64c9.4 9.4 24.6 9.4 33.9 0L369 209z"/></svg>

and running without gt::html() outputs the correct icon.

Expected result

I would expect to see the icon circle-check in the column fa_icon like in my previous tables: image

Session info

r$> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

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

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

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

loaded via a namespace (and not attached):
 [1] gtable_0.3.4        ggplot2_3.4.4       remotes_2.4.2.1     processx_3.8.3     
 [5] callr_3.7.3         paletteer_1.6.0     tzdb_0.4.0          ps_1.7.6           
 [9] vctrs_0.6.5         tools_4.3.1         generics_0.1.3      curl_5.2.0         
[13] parallel_4.3.1      tibble_3.2.1        fansi_1.0.6         blob_1.2.4         
[17] pkgconfig_2.0.3     httpgd_1.3.1        desc_1.4.2          gt_0.10.1          
[21] lifecycle_1.0.4     compiler_4.3.1      farver_2.1.1        stringr_1.5.1      
[25] textshaping_0.3.6   munsell_0.5.0       fontawesome_0.5.2   janitor_2.2.0      
[29] snakecase_0.11.1    httpuv_1.6.13       htmltools_0.5.7     sass_0.4.8         
[33] later_1.3.2         pillar_1.9.0        crayon_1.5.2        tidyr_1.3.1        
[37] gtExtras_0.5.0.9004 RPostgres_1.4.6     tidyselect_1.2.0    zip_2.3.0          
[41] digest_0.6.34       stringi_1.8.3       dplyr_1.1.4         purrr_1.0.2        
[45] rematch2_2.1.2      labeling_0.4.3      rprojroot_2.0.4     fastmap_1.1.1      
[49] grid_4.3.1          colorspace_2.1-0    cli_3.6.2           magrittr_2.0.3     
[53] pkgbuild_1.4.2      utf8_1.2.4          readr_2.1.5         withr_3.0.0        
[57] prettyunits_1.2.0   scales_1.3.0        promises_1.2.1      bit64_4.0.5        
[61] lubridate_1.9.3     timechange_0.3.0    bit_4.0.5           noventi_0.2.0      
[65] ragg_1.2.5          hms_1.1.3           openxlsx_4.2.5.2    V8_4.4.1           
[69] rlang_1.1.3         Rcpp_1.0.12         glue_1.7.0          juicyjuice_0.1.0   
[73] DBI_1.2.1           xml2_1.3.6          rstudioapi_0.15.0   vroom_1.6.5        
[77] jsonlite_1.8.8      R6_2.5.1            systemfonts_1.0.4   fs_1.6.3     
Cattiva commented 9 months ago

Never mind, just found out about gt::fmt_icon and the gt::from_column function from gt release 0.10.0. The following code does work without gtExtras and does exactly what I want:

tibble::tibble(
  fa_icon = "circle-check",
  fill_color = "darkgreen"
) |>
gt::gt() |>
gt::fmt_icon(
  fa_icon,
  fill_color = gt::from_column("fill_color")
)

I mean, the bug still persists in gtExtras but the function gt_fa_column seems redundant now, so no fix needed for me.

Thank you anyway for your awesome work :)

jthomasmock commented 9 months ago

Thanks for reporting! I agree that if you can get the function "upstream" that's the way to go!

However, I also can't reproduce the issue locally, as it seems to be working 🤷

tibble::tibble(
  fa_icon = "circle-check"
) |>
gt::gt() |>
gtExtras::gt_fa_column(
  fa_icon
) |> 
  gtExtras::gt_reprex_image()

Created on 2024-02-04 by the reprex package (v2.0.1)

rparrish-mercy commented 8 months ago

I'm still seeing the same thing after updating {gt} to 0.10.1 Running Tom's reprex: above:

tibble::tibble(
  fa_icon = "circle-check"
) |>
gt::gt() |>
gtExtras::gt_fa_column(
  fa_icon
) |> 
  gtExtras::gt_reprex_image()

file13c826802e40

Having tried the new gt::fmt_icon() function, I still need the gt_fa_column() function for a use case where only some rows have an 'attention' icon and others are left blank. Hoping you can re-open this issue and see if it's a relatively easy fix to get it working with {gt} 0.10.1.