I am working on a project in applied data analysis and was trying to add a click event to some precise nodes in the network G. I found some poor documentation on this topic and tried to implement this in my code. Here below is a simplified example, trying to make node 1 open a wikipedia page when eft-clicking on it through a json file read as options or interaction. The url is automatically opened without even having to click on the node and clicking n the node doesn't do anything.. It seems that Jupyter just ignores my "interaction" and "click" hierarchy. I am stucked and ask for your help! thanks a lot !
import webbrowser
import pyvis
from pyvis import network
from pyvis.network import Network
name = 'Freddie Mercury'
url = "https://en.wikipedia.org/wiki/"+name
def display_page(url):
webbrowser.open_new(url)
G = Network(height='400px', width='80%', bgcolor='white', notebook=True, font_color ='black')
G.add_node(1)
G.add_node(2)
G.add_edges([(1,2,4)])
options = {
"nodes":{
"font":{
"size": 50,
"bold":True
}
},
"edges":{
"color":'red',
"smooth":False
},
"physics":{
"barnesHut":{
"gravitationalConstant":-500000,
"centralGravity":12,
"springLength": 50,
"springConstant": 0.7,
"damping": 3,
"avoidOverlap": 10
}
},
"intercation":{
"click":{
"nodes": ["1"],
"event":[display_page(url)]
}}}
G.options=options
network.Network.show(G,'networkx_click_event.html')