d3graph icon indicating copy to clipboard operation
d3graph copied to clipboard

Trying to get example to work in google collab

Open ftrotter opened this issue 2 years ago • 3 comments

This basic code is from the example:

`!pip install d3graph from d3graph import d3graph, vec2adjmat

Create example network

source = ['node A','node F','node B','node B','node B','node A','node C','node Z'] target = ['node F','node B','node J','node F','node F','node M','node M','node A'] weight = [5.56, 0.5, 0.64, 0.23, 0.9, 3.28, 0.5, 0.45]

Convert to adjacency matrix

adjmat = vec2adjmat(source, target, weight=weight)

Initialize

d3 = d3graph()

Proces adjmat

d3.graph(adjmat)

Plot

d3.show()`

But this does not appear to work. It does seem to be generating the html, but not showing it in google collab.

Would it be possible to have some example code that shows how to get the project to work on that platform?

-ft

ftrotter avatar Mar 20 '22 16:03 ftrotter

True. it seems that Colab does not like running javascript. I need to look into this. I tried the underneath but did not work. It may give you some hints in the direction where you can look at.

from IPython.display import IFrame
IFrame(src='/tmp/tmppuhff_dn/d3graph.html', width=900, height=600)

erdogant avatar Mar 24 '22 15:03 erdogant

The IFrame model does indeed work in JupyterLab (I am not sure about collab) however due to security restrictions, the html file must be in the same directory as the notebook. So, even a fully qualified path to the file will give a 404 error, but just the filename, as long as it's in the same directory works.

I've gotten around this by using os.getcwd to get the working directory of the notebook and then saving the file explicitly where the notebook is. Works great.

JohnOmernik avatar Jul 24 '22 19:07 JohnOmernik

great! very helpful! I will implement your solution.

erdogant avatar Jul 26 '22 08:07 erdogant