jverma / networkxd3 Goto Github PK
View Code? Open in Web Editor NEWD3 JavaScript networkx Graphs in Python
D3 JavaScript networkx Graphs in Python
import networkx as nx
from rpy2.robjects.packages import importr
import rpy2.robjects as ro
import pandas as p
from rpy2.robjects import pandas2ri
pandas2ri.activate()
def simpleNetworkx(G):
ro.r('src = c()')
ro.r('target =c()')
ro.r('rdf=data.frame()')
df = p.DataFrame(data=G.edges())
df_r = pandas2ri.py2rpy(df) # <------------- use py2rpy
ro.globalenv['src'] = df_r[0]
ro.globalenv['target'] = df_r[1]
ro.r('rdf=data.frame(src,target)')
utils = importr('utils')
utils.chooseCRANmirror(ind=1)
try:
networkD3 = importr('networkD3')
except:
utils.install_packages('networkD3')
networkD3 = importr('networkD3')
try:
magrittr = importr('magrittr')
except:
utils.install_packages('magrittr')
magrittr = importr('magrittr')
ro.r('''simpleNetwork(rdf) %>% saveNetwork(file = 'Net.html')''')
return None`
setup.py
is mentioning data in Data/*.txt
but the directory appears missing from the repository.
git add Data/*.txt
before git commit
and git push
in the root directory of the original clone might be a way to fix this. An another way would be to remove Data/*.txt
from setup.py
.
[Apologies in advance if it transpires that this issue is due to my newbie-ness.]
After installing NetworkxD3 as described and trying to run the MWE provided (see end), I get the following error: "NameError: name 'simpleNetworkx' is not defined"
Can you help? I am running Python 2.7.10.
Thanks,
Lisa
import networkx as nx
from NetworkxD3 import simpleNetworkx
G = nx.Graph()
H = ["A","B","C","D","E","F","G", "H","I","J"]
G.add_nodes_from(H)
G.add_edges_from([("A","B"), ("A","C"), ("A","D"), ("A","J"), ("B","E"), ("B","F"),
("C","G"),("C","H"), ("D","I")])
simpleNetworkx(G)
I tried to open NetworkxD3example.ipynb
, but neither Github, nbviewer nor my local jupyter installation could handle it. Here's jupyter's error message:
Unreadable Notebook: /tmp/NetworkxD3/NetworkxD3example.ipynb NotJSONError('Notebook does not appear to be JSON: u\'{\\n "cells": [\\n {\\n "cell_type": "...',)
I had to downgrade to Pandas 0.19.1 due to another error. Now I get the following error. Please provide the package versions you used:
import networkx as nx
from NetworkxD3.NetworkxD3 import simpleNetworkx
from IPython.display import IFrame
G = nx.Graph()
H = ["A","B","C","D","E","F","G", "H","I","J"]
G.add_nodes_from(H)
G.add_edges_from([("A","B"), ("A","C"), ("A","D"), ("A","J"), ("B","E"), ("B","F"),
("C","G"),("C","H"), ("D","I")])
simpleNetworkx(G)
IFrame('Net.html', width=400, height=400)
PandasError Traceback (most recent call last)
in ()
9 ("C","G"),("C","H"), ("D","I")])
10
---> 11 simpleNetworkx(G)
12 IFrame('Net.html', width=400, height=400)
/vagrant/JMB/NetworkxD3/NetworkxD3/NetworkxD3.py in simpleNetworkx(G)
49 ro.r('rdf=data.frame()')
50
---> 51 df = p.DataFrame(G.edges())
52
53 df_r = com.convert_to_r_dataframe(df)
~/anaconda3/envs/normal/lib/python3.6/site-packages/pandas/core/frame.py in init(self, data, index, columns, dtype, copy)
343 copy=False)
344 else:
--> 345 raise PandasError('DataFrame constructor not properly called!')
346
347 NDFrame.init(self, mgr, fastpath=True)
PandasError: DataFrame constructor not properly called!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.