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

Support for .pptx output #97

Open
npelikan opened this issue Dec 7, 2018 · 3 comments
Open

Support for .pptx output #97

npelikan opened this issue Dec 7, 2018 · 3 comments

Comments

@npelikan
Copy link

@npelikan npelikan commented Dec 7, 2018

Hi! Playing around with your package and the dev version of RStudio, I've noticed that gt tables don't print with any formatting when output to .pptx, instead just printing raw text. Two solutions I can see, in ascending order of complexity: 1) Output the formatted table as an immutable image and 2) Output into a native .pptx tables

Reprex:

---
title: "pptx_test"
output: powerpoint_presentation
---

```{r setup, include=FALSE}
library(gt)
library(tidyverse)
library(glue)
```

## Slide with GT output

```{r cars, echo = FALSE}
# Define the start and end dates for the data range
start_date <- "2010-06-07"
end_date <- "2010-06-14"

# Create a gt table based on preprocessed
# `sp500` table data
sp500 %>%
  dplyr::filter(date >= start_date & date <= end_date) %>%
  dplyr::select(-adj_close) %>%
  dplyr::mutate(date = as.character(date)) %>%
  gt() %>%
  tab_header(
    title = "S&P 500",
    subtitle = glue::glue("{start_date} to {end_date}")
  ) %>%
  fmt_date(
    columns = vars(date),
    date_style = 3
  ) %>%
  fmt_currency(
    columns = vars(open, high, low, close),
    currency = "USD"
  ) %>%
  fmt_number(
    columns = vars(volume),
    scale_by = 1 / 1E9,
    pattern = "{x}B"
  )
```
@rich-iannone
Copy link
Member

@rich-iannone rich-iannone commented Dec 10, 2018

Thanks for the feature request, and it sounds like a good one!

The first option would be great and certainly would be great for a variety of use cases (and it's requested in #96). I'm not sure how much work the second option would entail but I agree it would be a step up from the first option.

I've done some looking into the first option (image output) and I'm trying to find a solution. It seems like using webshot might work. Another option (difficult though) would be to create SVG output (in much the same way we create HTML output) and then use rsvg to convert to different image formats. There are probably other solutions as well (I'm hoping they might be easier/better).

@npelikan
Copy link
Author

@npelikan npelikan commented Dec 17, 2018

RE the second option: https://github.com/davidgohel/flextable looks like it has knitr+pptx support

@namenick42
Copy link

@namenick42 namenick42 commented Mar 5, 2019

Hi,
As a work around the webshot package works for me:

gt <- table

library(htmltools)
save_html(html(gt::as_raw_html(gt )), "table.html", background = "white")
webshot::webshot(url = "table.html", file = "table.png")

With futher options via webshot.

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

3 participants