Skip to content
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

gt_plt_bar_stack() does not render the heading html #139

Open
Deflagration opened this issue Oct 25, 2024 · 4 comments
Open

gt_plt_bar_stack() does not render the heading html #139

Deflagration opened this issue Oct 25, 2024 · 4 comments
Assignees

Comments

@Deflagration
Copy link

From the gt_plt_bar_stack() vignette:

library(gt)
library(dplyr)
library(gtExtras)

ex_df <- dplyr::tibble(
  x = c("Example 1","Example 1",
        "Example 1","Example 2","Example 2","Example 2",
        "Example 3","Example 3","Example 3","Example 4","Example 4",
        "Example 4"),
  measure = c("Measure 1","Measure 2",
              "Measure 3","Measure 1","Measure 2","Measure 3",
              "Measure 1","Measure 2","Measure 3","Measure 1","Measure 2",
              "Measure 3"),
  data = c(30, 20, 50, 30, 30, 40, 30, 40, 30, 30, 50, 20)
)


tab_df <- ex_df %>%
  group_by(x) %>%
  summarise(list_data = list(data))

tab_df

ex_tab <- tab_df %>%
  gt() %>%
  gtExtras::gt_plt_bar_stack(column = list_data)

ex_tab

Description

Heading renders Rstudio and in Quarto dashboards as html raw.

Expected result

The heading should be a stylized gt() table with a beautiful header.

Session info

R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

time zone: America/Chicago
tzcode source: internal

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

other attached packages:
[1] gtExtras_0.5.0.9005 dplyr_1.1.4 gt_0.11.1

loaded via a namespace (and not attached):
[1] gtable_0.3.5 compiler_4.4.1 rematch2_2.1.2
[4] tidyselect_1.2.1 xml2_1.3.6 systemfonts_1.1.0
[7] scales_1.3.0 textshaping_0.4.0 fastmap_1.2.0
[10] ggplot2_3.5.1 R6_2.5.1 paletteer_1.6.0
[13] labeling_0.4.3 generics_0.1.3 knitr_1.48
[16] tibble_3.2.1 munsell_0.5.1 svglite_2.1.3
[19] pillar_1.9.0 rlang_1.1.4 utf8_1.2.4
[22] xfun_0.48 sass_0.4.9 cli_3.6.3
[25] withr_3.0.1 magrittr_2.0.3 digest_0.6.37
[28] grid_4.4.1 rstudioapi_0.17.0 fontawesome_0.5.2
[31] lifecycle_1.0.4 vctrs_0.6.5 glue_1.8.0
[34] farver_2.1.2 ragg_1.3.3 fansi_1.0.6
[37] colorspace_2.1-1 tools_4.4.1 pkgconfig_2.0.3
[40] htmltools_0.5.8.9000

@rlohne
Copy link

rlohne commented Oct 27, 2024

A workaround that worked for me on Mac was to downgrade R to 4.3.3.

@Deflagration
Copy link
Author

A workaround that worked for me on Mac was to downgrade R to 4.3.3.

Thanks for this. Yeah, suspect that the htmltools::HTML() renders slightly differently. I ended up re-writing gt_plt_bar_stack() with a plain title as my own function.

@valderpan
Copy link

Hi Deflagration,

I had a similar problem and got the following results using your data.
tmp

You can see that the column names of the list_data column are in the raw html format.
If it is possible, can you tell me how to solve this problem?

Session info
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 15.1.1

Matrix products: default

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] gtExtras_0.5.0 dplyr_1.1.4 gt_0.11.1

loaded via a namespace (and not attached):
[1] tidyselect_1.2.1 xfun_0.49 rematch2_2.1.2 purrr_1.0.2 paletteer_1.6.0 colorspace_2.1-1
[7] vctrs_0.6.5 generics_0.1.3 htmltools_0.5.8.1 stats4_4.2.1 yaml_2.3.10 utf8_1.2.4
[13] rlang_1.1.4 pillar_1.9.0 glue_1.8.0 withr_3.0.2 BiocGenerics_0.44.0 readxl_1.4.3
[19] GenomeInfoDbData_1.2.9 lifecycle_1.0.4 zlibbioc_1.44.0 munsell_0.5.1 gtable_0.3.6 cellranger_1.1.0
[25] ragg_1.2.5 fontawesome_0.5.3 evaluate_1.0.1 labeling_0.4.3 knitr_1.49 IRanges_2.32.0
[31] fastmap_1.2.0 GenomeInfoDb_1.34.9 fansi_1.0.6 scales_1.3.0 S4Vectors_0.36.2 XVector_0.38.0
[37] farver_2.1.2 systemfonts_1.0.4 textshaping_0.3.6 ggplot2_3.5.1 digest_0.6.37 GenomicRanges_1.48.0
[43] grid_4.2.1 rprojroot_2.0.4 here_1.0.1 cli_3.6.3 tools_4.2.1 bitops_1.0-9
[49] magrittr_2.0.3 sass_0.4.9 RCurl_1.98-1.16 tibble_3.2.1 pkgconfig_2.0.3 xml2_1.3.6
[55] rmarkdown_2.29 svglite_2.1.3 rstudioapi_0.17.1 R6_2.5.1 compiler_4.2.1

@Jean-Luc314
Copy link

Jean-Luc314 commented Nov 25, 2024

I had a similar problem, I used the below as a temporary solution:

# `ex_tab` from above
html_label <- ex_tab$`_boxhead`$column_label[[match("list_data", names(ex_tab$`_data`))]][[1]]

ex_tab  |> gt::cols_label(list_data = html_label)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants