I have built my network with the visNetwork package in Shiny. I would like to click on a node and then display the information about the node from a dataframe. I have been able to do this for scatterplots with the click and nearpoint functions, such as the ones in the Shiny example shown here: http://shiny.rstudio.com/gallery/plot-interaction-selecting-points.html.
For my network, I have tried:
server <- function(input, output) {
output$network <- renderVisNetwork({
visNetwork(my.nodes, my.edges,
height = "100%", width = "100%",
main = "") %>%
visEvents(hoverNode = "function(nodes){
Shiny.onInputChange('current_node_id',nodes);
;}",
click = "function(){
Shiny.onInputChange('click',{node: current_node_id});
;}"
)
})
output$shiny_return <- renderPrint({
if(!is.null(input$current_node_id)){
nearPoints(node.data,click$node, addDist = TRUE )
}
})
ui <- fluidPage(
visNetworkOutput("network"),
verbatimTextOutput("shiny_return")
)
But, I get an error saying "click object not found"
Thank you for your help.
Warning: Error in rbind.data.frame: invalid list argument: all variables should have the same length
. I am using the same code and it works for the example you provided. – Whiting