0

I am working in R Markdown, knitting to PDF.

I thought the following code should create a table with a local image, but it is not working. Any help would be greatly appreciated!


column1 <- c("1", "2", "3")
column2 <- c("a", "b", "c")
column3 <- c("x", "y", "z")

dat <- data.frame(column1, column2, column3)

dat$column1[1] <- "![image1](green.png){ width=25px }"

print(kable(dat))

VBtech
  • 1
  • You may find the answer here: https://stackoverflow.com/questions/25106481/add-an-image-to-a-table-like-output-in-r – Bruno Vidigal Aug 04 '20 at 07:15
  • Does this answer your question? [Add an image to a table-like output in R](https://stackoverflow.com/questions/25106481/add-an-image-to-a-table-like-output-in-r) – JBGruber Aug 04 '20 at 07:59

1 Answers1

1
---
title: "pic in column"
author: "test"
date: "2014/08/03"
output: html_document
---

```{r results='asis'}
library(knitr)
column1 <- c("1", "2", "3")
column2 <- c("a", "b", "c")
column3 <- c("x", "y", "z")

dat <- data.frame(column1, column2, column3)

dat$column1<- sprintf('![](green.png)')

print(kable(dat))
```

enter image description here

I just used the link in the comments and fit your question into the code. if you wanted different pictures for each row, you maybe need to save the file names into a vector. In the example you could also use images from a webpage

Daniel_j_iii
  • 3,041
  • 2
  • 11
  • 27
  • 1
    Hey Daniel! Thanks so much for the effort put into the response. Unfortunately this solution doesn't work with PDF output, which is what I'm struggling with at the moment. Really appreciate it though! – VBtech Aug 18 '20 at 15:02
  • What if you render it to HTML and then print to PDF? – Daniel_j_iii Aug 18 '20 at 16:37