rimagevisnetwork

Make nodes as images in R with visNetwork lib


folks! I want to insert pictures instead of nodes on the graph. I used the visNetwork library on the vis.js engine. While searching the answer I found the article https://datastorm-open.github.io/visNetwork/image_icon.html, but I've tried to repeat written code myself, unfortunately it didn't draw nodes as images in Rstudio.

 setwd("/home/user/")
 path_to_images<-"Images/"
 nodes <- data.frame(id = 1:4, 
            shape = c("image", "circularImage"),
            image = paste0(path_to_images, 1:4, ".png"),
            label = "I'm an image")

 edges <- data.frame(from = c(2,4,3,3), to = c(1,2,4,2))

 visNetwork(nodes, edges, width = "100%") %>% 
     visNodes(shapeProperties = list(useBorderWithImage = TRUE)) %>%
     visLayout(randomSeed = 2)

Maybe the problem is in local path to images? I'll wait for answer, thanks!)


Solution

  • I've found the answer on my question. On my view the problem was in path to the images. I installed apache2 server on my ubuntu 18.04 and created a directory with photos,and then I've just changed the path_to_images variable on "http:127.0.0.1/Images/" and added an brokenImage option in visNodes:

     visNetwork(nodes, edges, width = "100%") %>%
         visNodes(shapeProperties = list(useBorderWithImage = TRUE),
                  brokenImage="http://localhost/Images/erroe.png") %>%
         visLayout(randomSeed = 2)
    

    And it finally started to work!)