ucsd-ccbb / visJS2jupyter

visJS2jupyter is a tool to bring the interactivity of networks created with vis.js into jupyter notebook cells
MIT License
78 stars 17 forks source link

Error importing visJS2jupyter.visJS_module #16

Closed syelda closed 6 years ago

syelda commented 6 years ago

Hi! I've gone through and installed everything according to the install instructions. But when importing visJS2jupyter.visJS_module, I get the following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-31-342177aa17ad> in <module>()
      1 import matplotlib as mpl
----> 2 import visJS2jupyter.visJS_module

~/anaconda/lib/python3.6/site-packages/visJS2jupyter/visJS_module.py in <module>()
     21 import networkx as nx
     22 
---> 23 Javascript("https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.js")
     24 
     25 def visjs_network(nodes_dict, edges_dict,

~/anaconda/lib/python3.6/site-packages/IPython/core/display.py in __init__(self, data, url, filename, lib, css)
    973         self.lib = lib
    974         self.css = css
--> 975         super(Javascript, self).__init__(data=data, url=url, filename=filename)
    976 
    977     def _repr_javascript_(self):

~/anaconda/lib/python3.6/site-packages/IPython/core/display.py in __init__(self, data, url, filename, metadata)
    608 
    609         self.reload()
--> 610         self._check_data()
    611 
    612     def __repr__(self):

~/anaconda/lib/python3.6/site-packages/IPython/core/display.py in _check_data(self)
    657     def _check_data(self):
    658         if self.data is not None and not isinstance(self.data, str):
--> 659             raise TypeError("%s expects text, not %r" % (self.__class__.__name__, self.data))
    660 
    661 class Pretty(TextDisplayObject):

TypeError: Javascript expects text, not b'/**\r\n * vis.js\r\n * https://github.com/almende/vis\r\n *\r\n * A dynamic, browser-based visualization library.\r\n *\r\n * @version 4.20.1-SNAPSHOT\r\n 

I've cut off the error, as it is just a print out of the entire page from https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.js. So it appears that I am unable to load the vis.js file -- any ideas what I may be missing or doing wrong?

Thank you! Sylvana

syelda commented 6 years ago

If I change the Javascript() line in visJS_module.py to the following, it works fine: Javascript("$.getScript('https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.js')")

renswilderom commented 6 years ago

@syelda I run into exactly the same problem today, and your solution also worked for me! Thanks.

m1webste commented 6 years ago

I'm sorry that you ran into that problem! I've updated the github code to reflect this fix.

cldashie commented 5 years ago

Hi! I'm getting the same error as Sylvana when I try and import the library using import visJS2jupyter.visJS_module after installing using python3 -m pip install visJS2jupyter. Let me know if I'm doing something wrong!

Thanks, Cory

Chaoste commented 5 years ago

I just have the some problem. I guess you're also importing version 0.1.16 which is from March 2018. The fix is from May - you might wanna install it directly from github: pip install git+https://github.com/ucsd-ccbb/visJS2jupyter.git

cldashie commented 5 years ago

Thanks, Thomas - that worked!

almereyda commented 5 years ago

Thanks @Chaoste, this also worked for me.

@m1webste Could you imagine releasing an updated package to PyPi, just for convenience of not having to find this closed issue when running into the same error? According to https://github.com/ucsd-ccbb/visJS2jupyter/issues/17#issuecomment-390246797 this should have happened, but my naive install before finding the issue here let me run into this, too.

camiloromers commented 5 years ago

@syelda Thanks a lot, the solutions works well