2

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') 

2 Answers 2

2

You've misspelled "interaction", but are you sure the package pyvis actually has "click" as a configuration option under interaction?

From what I can gather from the documentation pyvis is a wrapper around visjs, and these are the interaction-configurations available under the network: https://visjs.github.io/vis-network/docs/network/interaction.html# I dont see any available "click" option, but maybe you could explore the "navigationButtons"?

Sign up to request clarification or add additional context in comments.

7 Comments

Is there any way to achieve the asker's purpose, using PyVis?
Not without first extending the capabilities of visjs, I would think
Did this code work? I am trying to do something similar, but I want the node to change color when clicked on
I suspect that this code has never worked, but similar things can be found in other libraries...
What other library would you suggest to visualize a Network and then be able to deploy it ?
|
-1

hello to fire event you do :

net = Network("1000px", "1000px") net.add_node(....) net.add_event_listener("selectNode", callback_function) 

1 Comment

add_event_listener doesn't appear to be a real part of the pyvis api...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.