Reputation: 145
I have a dataframe in R with a number of attributes about a bunch of sequence motifs. One of the columns contains a path to a png image of the motif. I want to use rmarkdown to save the file as an html page displaying the dataframe or table with all of the attributes and have the PNG images show up. I can't figure out how to do this.
Upvotes: 4
Views: 1879
Reputation: 28672
It's always good to start with some reproducible example:
df <- data.frame(name = c('bicycle', 'binoculars', 'globe'))
df$url <- paste0('http://fa2png.io/static/images/',
df$name, '_000000_64.png')
Call pander::pandoc.image
to render image markup from the above URLs in markdown:
library(pander)
df$url <- sapply(df$url, pandoc.image.return)
Render the markdown table:
pander(df)
Resulting in the following table:
-----------------------------------------------------------------------
name url
---------- ------------------------------------------------------------
bicycle 
binoculars 
globe 
-----------------------------------------------------------------------
That can be converted to HTML or whatever other format is required by e.g. pandoc
:
pandoc -t html
Upvotes: 5