Search code examples
flextableofficer

Adding flextable including images in PowerPoint


I'm trying to add a flextable object including an image to PowerPoint using officer. But the image disappears. I can reproduce the problem using the example David has posted hear

library(flextable)
library(tibble)
download.file("https://www.r-project.org/logo/Rlogo.png", destfile = "Rlogo.png")
pupil.tbl <- tribble(
    ~col1, ~col2, ~col3,
    "A", "B", "Rlogo.png",
    "C", "D", "Rlogo.png"
) 
pupil.tbl <- as.data.frame(pupil.tbl)

# display only col1 and col2
pupil.ft <- flextable(pupil.tbl, col_keys = c("col1", "col2") )

add_img_to_flextable <- function(ft, i, j){
display(
   ft, i=i, col_key = j, pattern = "{{att_tbl}}",
   formatters = list(# use col3 even if not displayed
        att_tbl ~ as_image(col3, src = col3, width = 1.29, height = 1)
   )
)
}

pupil.ft <- add_img_to_flextable(pupil.ft, i = 2, j = "col2")

If I run:

print(pupil.ft,preview='html')
print(pupil.ft,preview='docx')

everything works fine, but in PPTX format the image isn't shown anymore print(pupil.ft,preview='pptx')

Is this a known limitation of PowerPoint? Is there any workaround how to show the images inside a table?

Thanks,

Philipp


Solution

  • That is a known limitation of PowerPoint, it can not handle images in cells