如何使用 flextabale() 添加带有图像的列?

How to add a column with images using flextabale()?

我正在尝试向 table 添加一个包含图像的列: 在此示例中,我在每一行中使用相同的图像,但我的实际数据具有不同的图像。

library(flextable)
library(officer)

img.file <- file.path( R.home("doc"), "html", "logo.jpg" )
data = iris %>% mutate(path= img.file)
myft <- flextable( head(data))

我正在关注 fleaxtable table ,

中列出的示例
myft <- compose( myft, j = "path",
                 value = as_paragraph(
                   as_image(src = path, width = .20, height = .15),
                   " blah blah ",
                   as_chunk(Sepal.Length, props = fp_text(color = "red"))
                 ),
                 part = "body")

当我 运行 它时,我得到错误:

我尝试阅读文档,但找不到关于如何修复错误的任何解释。在我提供的代码中,它实际上向单元格添加了图像和文本“blah blah”,但我只想将路径呈现为图像。我尝试将代码缩短为以下内容:

myft <- compose( myft, j = "path",
                     value = as_paragraph(
                       as_image(src = path, width = .20, height = .15))
                     ),
                     part = "body")

但是没有用。 非常感谢您的帮助!

用错函数了! colformat_image() 成功了

myft <- colformat_image( myft, j = "path", width = .20, height = .15)