yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.36k stars 873 forks source link

Animation not rendering in powerpoint #2326

Closed shirdekel closed 3 months ago

shirdekel commented 4 months ago

I have the following qmd file, which renders fine in html (both animation formats work), but not in powerpoint (the default gif output shows up as a static photo and the mp4 comes out with "The picture can't be displayed"). As a word doc, the GIF works, and the mp4 doesn't. I also tried setting the gif chunk to fig.show: 'animate' and animation.hook: 'gifski', and the mp4 chunk to ffmpeg.format: 'mp4'.

---
title: "Minimal example"
format: pptx
---

```{r}
library(ggplot2)
library(gganimate)

p <- ggplot(airquality, aes(Day, Temp)) +
  geom_line(size = 2, colour = "steelblue") +
  transition_states(Month, 4, 1) +
  shadow_mark(size = 1, colour = "grey")

anim_save("test.mp4", p, renderer = ffmpeg_renderer())
## As GIF
p
## As mp4
knitr::include_graphics("test.mp4")

```r
xfun::session_info('knitr')
R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin23.0.0 (64-bit)
Running under: macOS Sonoma 14.2.1

Locale: en_AU.UTF-8 / en_AU.UTF-8 / en_AU.UTF-8 / C / en_AU.UTF-8 / en_AU.UTF-8

Package version:
  evaluate_0.23   graphics_4.3.2  grDevices_4.3.2 highr_0.10      knitr_1.45.13   methods_4.3.2   stats_4.3.2     tools_4.3.2    
  utils_4.3.2     xfun_0.42       yaml_2.3.8     

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

cderv commented 4 months ago

First thing, let's clarify the context here.

This is knitr repo and knitr is not responsible for PPTX output. It will only produce Markdown based on the cells results.

Your example is also using Quarto here which could behave differently, and add a layer of processing after knitr.

This is the Markdown content which is produced by knitr in Quarto context.

---
title: "Minimal example"
format: pptx
keep-md: true
---

::: {.cell}

:::

::: {.cell}
::: {.cell-output-display}
![](test_files/figure-pptx/unnamed-chunk-2-1.gif)
:::
:::

::: {.cell}
::: {.cell-output-display}
![](test.mp4)
:::
:::

it looks fine to me.

but not in powerpoint (the default gif output shows up as a static photo and the mp4 comes out with "The picture can't be displayed").

Gif is displaying correctly for me in the output.

POWERPNT_X01Jk1tCPg

Regarding Video, it is currently not supported by Pandoc itself:

So you'll need to add video manually in the PPTX file.

I also tried setting the gif chunk to fig.show: 'animate' and animation.hook: 'gifski'

This is also working on my side with latest versions of the tools.

---
title: "Minimal example"
format: pptx
keep-md: true
---

```{r}
#| fig-show: animate
#| animation-hook: gifski
library(ggplot2)
library(gganimate)

p <- ggplot(airquality, aes(Day, Temp)) +
  geom_line(size = 2, colour = "steelblue") +
  transition_states(Month, 4, 1) +
  shadow_mark(size = 1, colour = "grey")
## As GIF
p


So it does not seem there is any issue except the unsupported PPTX feature from Pandoc.