Home > Software engineering >  How to to insert R (interactive or not) graphics in the tooltips of a ggiraph?
How to to insert R (interactive or not) graphics in the tooltips of a ggiraph?

Time:04-24

I'd like ultimately to insert R (interactive or not) graphics in the tooltips of a ggiraph. Using an iframe as I successfully did before with leaflet, it would look like this:

library(ggplot2)
library(ggiraph)
library(htmltools)

p <- {ggplot()   
  aes(1,1, tooltip = "blabla")  
  geom_point_interactive()} %>% 
  girafe(ggobj = .)

save_html(p, file = "test.html") # I would use a loop to save many different graphs at the same time

{ggplot()   
    aes(1,1, tooltip = HTML("<iframe src='test.html' frameborder=0 width=300 height=300></iframe>"))  
    geom_point_interactive()} %>% 
  girafe(ggobj = .)

Unfortunately, I came with somewhat of a bug. Let's try:

{ggplot()   
    aes(1,1, tooltip = HTML("<iframe src='https://stackoverflow.com' frameborder=0 width=300 height=300></iframe>"))  
    geom_point_interactive()} %>% 
  girafe(ggobj = .)

In Firefox, it gives just a black square and in RStudio IDE it unexpectedly opens the site in a browser on mouse hover. enter image description here

  • Related