Search code examples
rflextable

Image not displayed in row of flextable on export ppt


i am trying to export to powerpoint a flextable that has rows with pictures on it, but not displaying on the generated powerpoint.

However it works well on the R studio Viewer.

Do you have any idea where the problem is coming from plz?

Thanks in advance

    library(kableExtra)
    library(flextable)
    library(officer)
    
    doc <- read_pptx()
    
    img.file <- file.path( R.home("doc"), "html", "logo.jpg" )
    
    myft <- flextable( head(mtcars), 
                       col_keys = c("am", "separator", "gear", "mpg", "drat", "qsec" ))
    
    myft <- compose( myft, i = ~ qsec > 18, j = "qsec", 
                     value = as_paragraph(as_image( src = img.file, width = .20, height = .15))
    )
    myft <- autofit(myft)
    myft
    
    doc <- add_slide(doc)
    
    doc <- ph_with(doc, value = myft, location = ph_location_template(top = 2, width = 4, type = "body"))
    
    print(doc, target = "./cars.pptx")
    system2('cmd', args = c('/c', '"./cars.pptx"'))

Solution

  • This is not possible with PowerPoint, you can read documentation here: https://davidgohel.github.io/flextable/articles/display.html#limitation-for-powerpoint-1

    Using images in flextable is not supported when output format is PowerPoint. This is not a choice nor an unimplemented feature. This is because PowerPoint is not able to embed images in a table cell. That’s a PowerPoint limitation.