0

With {knitr} & {DT}, we can embed image to DT and make a table with image and data altogether, but it generates ERROR when output as PDF, please advise how I can fix it?

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)

It works so far to generate a table with image and data altogether. But error pops out when output to 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.

Have add the always_allow_html: yes at YAML, but it just stop running. Please advise and many thanks.

Grec001
  • 1,111
  • 6
  • 20
  • 1
    I don't think you can use `datatable` in pdf – Matt Sep 09 '19 at 13:15
  • Thanks for advice. Let me try and feed back. Thanks! – Grec001 Sep 09 '19 at 13:19
  • i found the solution from yihui Xie himself. https://stackoverflow.com/questions/25106481/add-an-image-to-a-table-like-output-in-r by using `kable()`. Thanks for advice @Matt – Grec001 Sep 09 '19 at 13:53

0 Answers0