vis-network icon indicating copy to clipboard operation
vis-network copied to clipboard

Use that library in a Jupyter Notebook

Open cscetbon opened this issue 5 years ago • 7 comments
trafficstars

I'm trying to use your library in a Notebook but it requires a DOM which I don't have. Is there any way to do without or do you have an example on how to do it using Jupyter ?

cscetbon avatar Jan 22 '20 17:01 cscetbon

Hi @cscetbon,

I've never used or even heard of Jupyter so I can't really say anything here. However could you say something about the use case for this and what output you want to get? Because running this without a DOM seems quite useless to me.

Thomaash avatar Jan 22 '20 17:01 Thomaash

@Thomaash, in Jupyter notebooks you can display images inline. So if the vis-network has a way to provide an array of pixels or a stream object that can be used to extract those pixels I could use something like https://matplotlib.org/tutorials/introductory/images.html#importing-image-data-into-numpy-arrays

cscetbon avatar Jan 22 '20 21:01 cscetbon

I'm afraid there's no good way to do this. It's possible to get images from Vis Network. We do it for examples index but that's done by running a Chromium instance to render into a canvas in the DOM so that's only an option if you can prerender the images. It's also possible to convert the canvas into an image but then you have to have the canvas somewhere. In case you have access to document.createElement it may be possible to use the element as a container and get an image from the canvas even if it isn't in DOM but I've never tried it so I don't know if it actually works.

Other than that something would have to be implemented in Vis Network to support this (contribution opportunity here :wink:).

Thomaash avatar Jan 22 '20 21:01 Thomaash

@Thomaash I might be able to use something like https://stackoverflow.com/a/43514776

cscetbon avatar Jan 22 '20 21:01 cscetbon

@cscetbon check out https://www.codementor.io/@isaib.cicourel/visjs-visualization-in-jupyter-notebook-phgb3fjv0

sadams-rti-org avatar Mar 16 '20 01:03 sadams-rti-org

@cscetbon @Thomaash Here is an example of using VisJS in regular Jupyter notebook, we need to use require here. https://www.kaggle.com/evgenyskvortsov/another-visjs/edit

Here is an example of using it in Google CoLab, which treats JS differently, so we can do it plainly: https://colab.research.google.com/github/EvgSkv/logica/blob/main/examples/more/Generic-VisJS.ipynb

Here is an example of using an open-source python library that draws graphs with VisJS: https://colab.research.google.com/github/EvgSkv/logica/blob/main/examples/Logica_example_Drawing_Graphs.ipynb#scrollTo=snWJQtjDp0qA

Hope this helps. Let me know if you have any questions, or if this would be useful to add to any documentation.

EvgSkv avatar Jun 08 '21 19:06 EvgSkv

And then there is https://pyvis.readthedocs.io/en/latest/tutorial.html#using-pyvis-within-jupyter-notebook

motin avatar Jan 06 '22 20:01 motin