首页 > 解决方案 > {knitr}在{DT}中嵌入图像并输出为pdf时弹出错误,请指教

问题描述

使用{knitr} & {DT},我们可以将图像嵌入到DT中,将图像和数据一起制作一个表格,但是输出为PDF时会产生错误,请告知我该如何解决?</p>

yy = "c:/Program Files/RStudio/www/favicon.ico"

img_uri <- function(x) { sprintf('<img src="%s"/>', knitr::image_uri(x)) }

dat <- data.frame(
  country = c('rstudio'),
  flag = img_uri(yy))
    DT::datatable(dat, escape = FALSE)

到目前为止,它可以生成一个包含图像和数据的表格。但是输出到pdf时会弹出错误。

output file: 2019-09-05-EXP-report.knit.md

ERROR: Functions that produce HTML output found in document targeting latex 

output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:

  always_allow_html: yes

Note however that the HTML output will not be visible in non-HTML formats.

已添加always_allow_html: yesat YAML,但它只是停止运行。请指教,非常感谢。

标签: rknitr

解决方案


推荐阅读