Skip to content

Conversation

@teunbrand
Copy link
Contributor

Summary

This PR aims to fix #1701. Briefly, it swaps the html context for grid context in as_gtable().
This context will format text with as.character() only, to avoid the html escape mechanism that renders poorly in graphics.

Please be forewarned that I only have a partial understanding of how contexts work in {gt}, so somebody who is more familiar should double-check whether this is the correct approach.

Here is a reprex from the linked issue, notice that the symbols on the left are now rendered as actual symbols.

library(tibble)
devtools::load_all("~/packages/gt")
#> ℹ Loading gt

# symbol
gt0 <- tibble(symbol = c(">", "%", "£", "&")
              , value = c(100, 200, 300, 400)) |> 
  gt() |> 
  fmt_currency(currency = "GBP") |>
  as_gtable() |>
  plot()

Created on 2024-06-20 with reprex v2.1.0

The currency formatting is still quite poor as it displays 'GBP' instead of '£', but I'm not familiar enough with the codebase to know where this should be fixed (the 'how' is just passing unicode symbols).

Related GitHub Issues and PRs

Checklist

@rich-iannone rich-iannone self-requested a review June 21, 2024 00:25
Copy link
Member

@rich-iannone rich-iannone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@rich-iannone rich-iannone merged commit 2af68b7 into rstudio:master Jun 21, 2024
@teunbrand teunbrand deleted the grid_text_no_escape_html branch June 21, 2024 05:38
@olivroy
Copy link
Collaborator

olivroy commented Jul 15, 2024

I am working on a PR (#1788).

I am able to achieve the following

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

Successfully merging this pull request may close these issues.

as_gtable() does not render html math symbols

3 participants