Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sg_zoom_p doesn't work for me #14

Open
shw079 opened this issue Dec 15, 2019 · 2 comments
Open

sg_zoom_p doesn't work for me #14

shw079 opened this issue Dec 15, 2019 · 2 comments

Comments

@shw079
Copy link

shw079 commented Dec 15, 2019

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
Copy link
Owner

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
Copy link
Author

shw079 commented Dec 16, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants