Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to get example to work in google collab #4

Open
ftrotter opened this issue Mar 20, 2022 · 3 comments
Open

Trying to get example to work in google collab #4

ftrotter opened this issue Mar 20, 2022 · 3 comments

Comments

@ftrotter
Copy link

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

@erdogant
Copy link
Owner

erdogant commented Mar 24, 2022

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)

@JohnOmernik
Copy link

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.

@erdogant
Copy link
Owner

great! very helpful! I will implement your solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants