JohnCoene / sigmajs

Σ sigma.js for R
http://sigmajs.john-coene.com
Other
72 stars 7 forks source link

sg_zoom_p doesn't work for me #14

Open shw079 opened 4 years ago

shw079 commented 4 years ago

Hi, I am trying to use the function sg_zoom_p so that upon clicking on a node, I would zoom onto that node. However, I can't get that working and I cannot find an example in the documentation. I did something like this, where output$sg <- renderSigmajs({...}):

observeEvent(input$sg_click_node, {
    sigmajsProxy("sg") %>% 
      sg_zoom_p(id = input$sg_click_node$id)
  })

When I click on a node, nothing has changed. Do you know what I am doing wrong here, or could you provide an example of how to do that? Thanks!

JohnCoene commented 4 years ago

If you are using the development version from Github, I have had to make changes to the way events are handled. Before every event was sent back to the R server which caused the visualisation to lag on large graphs. You now have to specify the events you want to capture with sg_events.

Does this work for you?

library(shiny)
library(sigmajs)

ui <- fluidPage(
  sigmajsOutput("sg", height = "100vh")
)

server <- function(input, output, session) {

  nodes <- sg_make_nodes(100)
  edges <- sg_make_edges(nodes)

  output$sg <- renderSigmajs({
    sigmajs() %>% 
      sg_nodes(nodes, id, size, color) %>% 
      sg_edges(edges, id, source, target) %>% 
      sg_layout() %>% 
      sg_events("clickNode")
  })

  observeEvent(input$sg_click_node, {
    sigmajsProxy("sg") %>% 
      sg_zoom_p(input$sg_click_node$id)
  })

}

shinyApp(ui, server)
shw079 commented 4 years ago

Thanks a lot for your reply! Yes the above codes work but it doesn't seem to zoom on the correct node, although the node id is specified to be the node clicked.