-
Notifications
You must be signed in to change notification settings - Fork 214
Render SVG cells as images in as_gtable()
output.
#1655
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
Conversation
Here are some example of flags and nanoplots. library(gt)
countrypops |>
dplyr::filter(year == 2021) |>
dplyr::filter(grepl("^S", country_name)) |>
dplyr::arrange(country_name) |>
dplyr::select(-country_code_3, -year) |>
dplyr::slice_head(n = 10) |>
gt() |>
cols_move_to_start(columns = country_code_2) |>
fmt_flag(columns = country_code_2) |>
as_gtable(plot = TRUE) |>
invisible() illness |>
dplyr::slice_head(n = 10) |>
gt(rowname_col = "test") |>
tab_header("Partial summary of daily tests performed on YF patient") |>
cols_hide(columns = c(starts_with("norm"), units)) |>
cols_nanoplot(
columns = starts_with("day"),
new_col_name = "nanoplots",
new_col_label = "Progression"
) |>
cols_align(align = "center", columns = nanoplots) |>
as_gtable(plot = TRUE) |>
invisible() sza |>
dplyr::filter(latitude == 20 & tst <= "1200") |>
dplyr::select(-latitude) |>
dplyr::filter(!is.na(sza)) |>
dplyr::mutate(saa = 90 - sza) |>
dplyr::select(-sza) |>
tidyr::pivot_wider(
names_from = tst,
values_from = saa,
names_sort = TRUE
) |>
gt(rowname_col = "month") |>
tab_header(
title = "Solar Altitude Angles",
subtitle = "Average values every half hour from 05:30 to 12:00"
) |>
cols_nanoplot(
columns = matches("0"),
plot_type = "bar",
missing_vals = "zero",
new_col_name = "saa",
plot_height = "2.5em",
options = nanoplot_options(
data_bar_stroke_color = "GoldenRod",
data_bar_fill_color = "DarkOrange",
y_val_fmt_fn = function(x) paste0(vec_fmt_number(x, decimals = 1), "\u00b0")
)
) |>
tab_options(
table.width = px(400),
column_labels.hidden = TRUE
) |>
cols_align(
align = "center",
columns = everything()
) |>
as_gtable(plot = TRUE) |>
invisible() Created on 2024-05-08 with reprex v2.1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thank you @teunbrand for contributing this! |
Summary
This PR aims to fix #1652.
Briefly, in the
as_gtable()
approach, it renders cells with the<svg>
tags using {rsvg} into raster images. It uses a regex pattern to recognise the tag and switches from a 'render plain text' mode to 'render svg' mode via a new internal functionrender_grid_svg()
. Most of this function's body is just trying to parse dimensions from the svg string.Related GitHub Issues and PRs
as_gtable()
output #1652Checklist
testthat
unit tests totests/testthat
for any new functionality.