datastorm-open / visNetwork

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

visUpdateNodes, nodes not returning to correct position, returning to the center of the graph #440

Open gustavoborba13 opened 2 years ago

gustavoborba13 commented 2 years ago

I have been trying to create a visNetwork graph that changes with a date input. The visRemoveNodes works fine when I decrease the date range. but the visUpdateNodes returns all nodes to the center of the graph when range is increased.

I have tried using visGetNodes to get coordinates, but when i include it into the code, it gives me an error when changing the date range.

  myVisNetworkProxy <- visNetworkProxy("mynetwork")

  observeEvent(input$mynetwork_initialized,{
    myVisNetworkProxy %>% visGetNodes(input = "nodes_coord")
  })  

  observe({
    #date filter
    date.filtered.edges <- edges.net %>%
      slice(-c(which(edges.net$date >= input$date)))

    date.filtered.nodes <- nodes.net %>%
      slice(c(which(nodes.net$id %in%  c(date.filtered.edges$from, date.filtered.edges$to))))%>%
      mutate(coords = input$nodes_coord)

    hiddenNodes <- anti_join(nodes.net, date.filtered.nodes)
    visRemoveNodes(myVisNetworkProxy, id = hiddenNodes$id)
    visUpdateNodes(myVisNetworkProxy, nodes = date.filtered.nodes)

  })
camillebordes commented 1 year ago

Have a look at this thread: https://github.com/datastorm-open/visNetwork/issues/262