datastorm-open / visNetwork

R package, using vis.js library for network visualization
Other
545 stars 125 forks source link

Graph takes a long time to display #393

Open LeoJavaAI opened 4 years ago

LeoJavaAI commented 4 years ago

My code is below, Currently for 32000 observations it takes more than 20 minutes, I have more 100000 observations how can I expedite the process?

` to <- df %>% distinct(to) %>% rename(label = to)

from <- df %>%
  distinct(from) %>%
  rename(label = from)

nodes <- full_join(to, from, by = "label")

nodes <- nodes %>% rowid_to_column("id")

per_route <- df %>%  
  group_by(from, to) %>%
  summarise(weight = n()) %>% 
  ungroup()

edges <- per_route %>% 
  left_join(nodes, by = c("to" = "label")) %>% 
  rename(to = id)

edges <- edges %>% 
  left_join(nodes, by = c("from" = "label")) %>% 
  rename(from = id)

edges <- select(edges, from, to, weight)

visNetwork(nodes, edges) %>%
  visPhysics(stabilization = FALSE) %>%
  visIgraphLayout() %>%
  visEdges(arrows = "from")`