trying to get node labels to be shown only on nodes that have been selected.
I found a similar question that wanted to only show edge labels on hover. The solution was this:
nodes <- data.frame(id = 1:3, label = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3), label = "Edge label", font.size = 0)
visNetwork(nodes, edges) %>%
visInteraction(hover = T) %>%
visEvents(hoverEdge = "function(e){
this.body.data.edges.update({id: e.edge, font: {size : 14}});
}") %>%
visEvents(blurEdge = "function(e){
this.body.data.edges.update({id: e.edge, font: {size : 0}});
}")
I've tried modifying this but I don't think I'm doing the javascript part right, I know JS hardly at all.
nodes <- data.frame(id = 1:3, label = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3), label = "Edge label", font.size = 0)
visNetwork(nodes, edges) %>%
visInteraction(hover = T) %>%
visEvents(selectNode= "function(e){
this.body.data.nodes.update({id: e.node, font: {size : 14}});
}") %>%
visEvents(deselectNode= "function(e){
this.body.data.nodes.update({id: e.node, font: {size : 0}});
}")
This instead causes a new node to be created every time I select or deselect a node. While sitting and clicking on them was a fun way to crash my Rsession, it unfortunately hasn't solved my problem.
I'm sure this is a simple fix but I've been through the visNetwork documentation and I'm just not finding what I need. Help appreciated!