I'm trying to add an image to a datatable in R form the DT
package. I fount this question: How to embed an image in a cell a table using DT, R and Shiny and it works for the image that's online. But when I tried to add a image that i have locally (created with R
) it just doesn't come up. This is an example of my problem:
x = rnorm(1000)
png(paste0("Graficas/test.png"))
Plot = plot(x, type = "l")
dev.off()
camino = '<img src="Graficas/test.png" height="30"></img>'
data = data.frame(0.5,camino)
datatable(data, escape = FALSE)
and I can't understand why its happening
This is one way to do it (by embedding base64 encoded images and using that for the
src
).First we'll make a small helper:
That will let us make a data uri. We're slurping up the whole file and converting it to base64 then doing a bit more formatting before sticking the entire blob into the
src
attribute.This is what a 1x1 pixel PNG looks like encoded that way:
So, we just do the same with the one you created:
Yours is having an issue b/c it's not "URI" and it has no way of pulling from the local system. It might work in a browser context with a
file://…
URL.