Vlad Vlad - 1 year ago 104
R Question

Rmarkdown: writing html with variables

How do I add HTML inside a code block in Rmarkdown in order to use variables in the HTML code?

For example, this works:

```{r, echo=FALSE}
#some R code
<div><img src='http://example.com/image.jpg'></div>

This doesn't work:

```{r, echo=FALSE}
my_image <- "image.jpg"
html(paste0("<div><img src='http://example.com/",my_image,"'></div> ")

Answer Source

You can use tags from library(htmltools)

```{r, echo=FALSE}

my_image <- "http://example.com/myImage.jpg"
tags$div(tags$img(src = my_image))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download