knitr icon indicating copy to clipboard operation
knitr copied to clipboard

Animation not rendering in powerpoint

Open shirdekel opened this issue 1 year ago • 1 comments

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())
```

```{r}
## As GIF
p
```

```{r}
## As mp4
knitr::include_graphics("test.mp4")
```


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

  • [x] I have fully read the issue guide at https://yihui.org/issue/.
  • [x] I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • [x] I have learned the Github Markdown syntax, and formatted my issue correctly.

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

shirdekel avatar Feb 19 '24 04:02 shirdekel

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:

  • https://github.com/jgm/pandoc/issues/7773

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")
```

```{r}
## As GIF
p
```

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

cderv avatar Feb 19 '24 11:02 cderv