I'm trying to server a ggplot as an svg in rShiny. This SVG has hyperlinks embedded into the y-axis labels.
I figured out that plotOutput won't cut it, so i'm using imageOutput/renderImage.
renderImage({
d = dataForHeatmap()
p = ggplot(d,aes(x=x,y=y,fill=some_fill)) + geom_tile(colour="white", linewidth=0.25)
width <- session$clientData$output_heatData_width
height <- session$clientData$output_heatData_height
ratio = width/height
tf1 <- tempfile(fileext = ".svg")
ggsave( tf1 , p, width=7*ratio,height=7)
xml <- read_xml(tf1)
xml %>%
xml_find_all(xpath="//d1:text") %>%
keep(xml_text(.) %in% names(links)) %>%
xml_add_parent("a", "xlink:href" = "https://www.youtube.com/watch?v=j8PxqgliIno", target = "_blank")
write_xml(xml, tf2 <- tempfile(fileext = ".svg"))
return(list(src = normalizePath(tf2), width = width, height = height, contentType = "image/svg+xml", alt="Histogram"))
}, deleteFile = TRUE)
This does the trick of serving the svg, but the links are not clickable. The issue seems to be the fact that the svg gets served in an "img" tag (this post).
I could go the suggested way, but i'm also using the click, dblclick and hover features of the imageOutput. I'd basically have to fully reimplement all of this for the uiOutput?
Is there a better way to achieve this?
Playing around with the content type returned did not do much. There is supposed to be a way to get renderImage to return a div instead of an img tag, but i was unable to do that.