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

Hover over edges not working #1

Closed
kyleweise opened this issue Jul 9, 2018 · 3 comments
Closed

Hover over edges not working #1

kyleweise opened this issue Jul 9, 2018 · 3 comments

Comments

@kyleweise
Copy link

Hello, very interested in this package and it is very well documented so kudos for that! However, I'm running into a problem when I try to capture hovering over edge events. Following this as a guide, here is my code:

library(shiny)
library(sigmajs)

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

ui <- fluidPage(
  sigmajsOutput("sg"),
  p("Hover over a node or edge"),
  verbatimTextOutput("hoverNode"),
  verbatimTextOutput("hoverEdge")
)

server <- function(input, output){
  output$sg <- renderSigmajs({
    sigmajs() %>%
      sg_nodes(nodes, id, size, color) %>%
      sg_edges(edges, id, source, target)
  })

  # capture node hover
  output$hoverNode <- renderPrint({
    paste0("This is node number: ", input$sg_over_node[["id"]])
  })
  # capture edge hover
  output$hoverEdge <- renderPrint({
    paste0("This is edge number: ", input$sg_over_edge[["id"]])
  })
}

shinyApp(ui, server) # run

As I move my mouse around, it captures the node hovering events just fine, but displays nothing when hovering over an edge. Is this a bug or am I doing something incorrectly?

Thanks!

-Kyle

> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_1.1.0        igraph_1.2.1       sigmajs_0.1.1.9000

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17     rstudioapi_0.7   bindr_0.1.1      magrittr_1.5     devtools_1.13.6  tidyselect_0.2.4
 [7] xtable_1.8-2     R6_2.2.2         rlang_0.2.1      dplyr_0.7.6      tools_3.5.0      withr_2.1.2     
[13] crosstalk_1.0.0  htmltools_0.3.6  yaml_2.1.19      digest_0.6.15    assertthat_0.2.0 tibble_1.4.2    
[19] crayon_1.3.4     bindrcpp_0.2.2   purrr_0.2.5      later_0.7.3      htmlwidgets_1.2  promises_1.0.1  
[25] memoise_1.1.0    glue_1.2.0       mime_0.5         compiler_3.5.0   pillar_1.2.3     jsonlite_1.5    
[31] httpuv_1.4.4.2   pkgconfig_2.0.1 
@JohnCoene
Copy link
Owner

Does it work by adding the follow to the graph?

sg_settings(enableEdgeHovering = TRUE)

Its one of the many settings, somewhat hidden I must admit.

@kyleweise
Copy link
Author

Hi John, I tried adding that line to my sigmajs() %>% ... pipe, along with raising the edgeHoverPrecision = 10 so that it would most certainty fire, and still no output.

@JohnCoene
Copy link
Owner

Goodness.

Apologies for the late "fix" @kyleweise . I found the problem, for edge hover to work one must:

  1. Add sg_settings(enableEdgeHovering = TRUE)
  2. And size to edges.

This works:

library(shiny)
library(sigmajs)

nodes <- sg_make_nodes(100)
edges <- sg_make_edges(nodes)
edges$size <- runif(1, 5, nrow(edges)) # add size

ui <- fluidPage(
    sigmajsOutput("sg"),
    p("Hover over a node or edge"),
    verbatimTextOutput("hoverNode"),
    verbatimTextOutput("hoverEdge")
)

server <- function(input, output){
    output$sg <- renderSigmajs({
        sigmajs() %>%
            sg_nodes(nodes, id, size, color) %>%
            sg_edges(edges, id, source, target, size) %>% # pass size
            sg_settings(enableEdgeHovering = TRUE)
    })
    
    # capture node hover
    output$hoverNode <- renderPrint({
        paste0("This is node number: ", input$sg_over_node[["id"]])
    })
    # capture edge hover
    output$hoverEdge <- renderPrint({
        paste0("This is edge number: ", input$sg_over_edge[["id"]])
    })
}

shinyApp(ui, server) # run

Let me know if this works, feel free to close if it's OK.

Thanks for reporting that, I will add this to the documentation.

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