I am trying to create an interactive network graph within Databricks R notebook using igraph and plotly. The sample code runs fine but I am not able to see the graph in the notebook after the run. Also, the same code renders an interactive graph in RStudio. Any inputs are appreciated. Thank you.
`library(plotly)
library(igraph)
library(igraphdata)
data(karate, package="igraphdata")
G <- upgrade_graph(karate)
L <- layout.circle(G)
#Create Vertices and Edges
vs <- V(G)
es <- as.data.frame(get.edgelist(G))
Nv <- length(vs)
Ne <- length(es[1]$V1)
#Create nodes
Xn <- L[,1]
Yn <- L[,2]
network <- plot_ly(x = ~Xn, y = ~Yn, mode = "markers", text = vs$label, hoverinfo = "text")
#Create edges
edge_shapes <- list()
for(i in 1:Ne) {
v0 <- es[i,]$V1
v1 <- es[i,]$V2
edge_shape = list(
type = "line",
line = list(color = "#030303", width = 0.3),
x0 = Xn[v0],
y0 = Yn[v0],
x1 = Xn[v1],
y1 = Yn[v1]
)
edge_shapes[[i]] <- edge_shape
}
#Create network
axis <- list(title = "", showgrid = FALSE, showticklabels = FALSE, zeroline = FALSE)
fig <- layout(
network,
title = 'Karate Network',
shapes = edge_shapes,
xaxis = axis,
yaxis = axis
)
fig`