Render SVG cells as images in as_gtable() output.#1655
Merged
rich-iannone merged 8 commits intorstudio:masterfrom May 8, 2024
Merged
Render SVG cells as images in as_gtable() output.#1655rich-iannone merged 8 commits intorstudio:masterfrom
as_gtable() output.#1655rich-iannone merged 8 commits intorstudio:masterfrom
Conversation
Contributor
Author
|
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 |
Member
|
Thank you @teunbrand for contributing this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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
testthatunit tests totests/testthatfor any new functionality.