I'm trying to display an image when hover on each row of a DT::datatable. I found a SO post that almost does what I'm looking for, but it repeats the same image for every row. What I want is to read the url from a data.frame column, and hopefully redefine the size. It's probably a very basic question for JS programmers,but my knowlegde in JS is almost none.
Here is a small example:
library(DT)
df <- data.frame(stringsAsFactors=FALSE,
a = rep("my stackoverflow Avatar",2),
b = rep("my stackoverflow Avatar",2),
url=c('https://d33wubrfki0l68.cloudfront.net/57299a1dcd979c623325f11bf5e5ce60f3d4eb00/e4602/wp-content/uploads/2018/10/black.png'
,'https://d33wubrfki0l68.cloudfront.net/ca4b0ae74fce141fb92ede7117b1c1928478c441/98350/wp-content/uploads/2018/10/rstudio-logo-gray.png')
)
datatable(df, options=list(columnDefs=list(list(
targets=1:1,render=DT::JS(
'function(data,row,type,meta) {
return "<a class=\'ItemsTooltip\' href=\'www.example.com\' target=\'_blank\'><img class=\'imgTooltip\' src=\'https://d33wubrfki0l68.cloudfront.net/57299a1dcd979c623325f11bf5e5ce60f3d4eb00/e4602/wp-content/uploads/2018/10/black.png\'/>" +
data + "</a>";
}'
)
))))
I would like to read the image url from the column url of df.
Any help will be much appreciated.