visNetwork in blogdown?

Ok, it works just like that

library(visNetwork)
nodes <- data.frame(id = 1:4)
edges <- data.frame(from = c(2,4,3,3), to = c(1,2,4,2))

visNetwork(nodes, edges, width = "100%") |> 
  visNodes(shape = "square", 
           color = list(background = "lightblue", 
                        border = "darkblue",
                        highlight = "yellow"),
           shadow = list(enabled = TRUE, size = 10)) |> 
  visLayout(randomSeed = 12) # to have always the same network     

But remember, to add several htmlwidgets from a single chunk (e.g.Β in a loop) you need to use knitr::knit_print

library(visNetwork)
nodes <- data.frame(id = 1:4)
edges <- data.frame(from = c(2,4,3,3), to = c(1,2,4,2))

vn1 <- visNetwork(nodes, edges, width = "100%") 

vn2 <- visNetwork(nodes, edges, width = "100%") |> 
  visNodes(shape = "square", 
           color = list(background = "lightblue", 
                        border = "darkblue",
                        highlight = "yellow"),
           shadow = list(enabled = TRUE, size = 10)) |> 
  visLayout(randomSeed = 12) # to have always the same network    

cat("\n\nFirst \n\n")
## 
## 
## First
knitr::knit_print(vn1)
cat("\n\nSecond \n\n")
## 
## 
## Second
knitr::knit_print(vn2)
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy