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

Using as_gtable(plot =TRUE) in Webr #1918

Open
2 of 3 tasks
bob-rietveld opened this issue Nov 5, 2024 · 1 comment
Open
2 of 3 tasks

Using as_gtable(plot =TRUE) in Webr #1918

bob-rietveld opened this issue Nov 5, 2024 · 1 comment

Comments

@bob-rietveld
Copy link

Prework

  • [ x] Read and agree to the code of conduct and contributing guidelines.
  • If there is already a relevant issue, whether open or closed, comment on the existing thread instead of posting a new issue.
  • [x ] For any problems you identify, a minimal reproducible example so the maintainer can troubleshoot. A reproducible example is:
    • Runnable: post enough R code and data so any onlooker can create the error on their own computer.
    • Minimal: reduce runtime wherever possible and remove complicated details that are irrelevant to the issue at hand.
    • [ x] Readable: format your code according to the tidyverse style guide.

Question

Hi,

Thanks for GT. it's an amazing library.

I am trying to capture the output of a gt object in an image. I am using webr in the browser so there are some constraints. I can capture ggplot images using Webr capture function, and I thought I could do the same using as_gtable(plot =TRUE). The only problem I run into is that rsvg has not been compiled as a wasm package, so I can't install it.

gt_save requires webshot2 to render the png, so that is not something I can easily install every session. Do you have any ideas, or options I could try ? Or should I try to get rsvg compiled to rwasm package ?

webr::install('gt')

illness |>
  dplyr::slice_head(n = 10) |>
  gt(rowname_col = "test") |>
  tab_header("Partial summary of daily tests performed on YF patient") |>
  tab_stubhead(label = md("**Test**")) |>
  cols_hide(columns = starts_with("norm")) |>
  fmt_units(columns = units) |>
  cols_nanoplot(
    columns = starts_with("day"),
    new_col_name = "nanoplots",
    new_col_label = md("*Progression*")
  ) |>
  cols_align(align = "center", columns = nanoplots) |>
  cols_merge(columns = c(test, units), pattern = "{1} ({2})") |>
  tab_footnote(
    footnote = "Measurements from Day 3 through to Day 8.",
    locations = cells_column_labels(columns = nanoplots)
  ) |> as_gtable( plot = TRUE )
@olivroy
Copy link
Collaborator

olivroy commented Nov 5, 2024

You can simply use

illness |>
  dplyr::slice_head(n = 10) |>
  gt(rowname_col = "test") |>
  tab_header("Partial summary of daily tests performed on YF patient") |>
  tab_stubhead(label = md("**Test**")) |>
  cols_hide(columns = starts_with("norm")) |>
  fmt_units(columns = units) |>
  cols_nanoplot(
    columns = starts_with("day"),
    new_col_name = "nanoplots",
    new_col_label = md("*Progression*")
  ) |>
  cols_align(align = "center", columns = nanoplots) |>
  cols_merge(columns = c(test, units), pattern = "{1} ({2})") |>
  tab_footnote(
    footnote = "Measurements from Day 3 through to Day 8.",
    locations = cells_column_labels(columns = nanoplots)
  ) |>
  plot()

Afterwards, you can use the plot pane to save an image

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

No branches or pull requests

2 participants