简体   繁体   中英

Visualize a networkx graph in plotly dash using a dataframe

I have a pandas dataframe that contains 3 columns, ['source', 'target', 'weight']. I have created a.networkx graph successfully and plotted it in the browser. The.networkx graph was created using the following line of code:

Graph = nx.from_pandas_edgelist(rules,source='source',target='target').

Using the.networkx library, it was easy to create the graph using only the above line of code, and setting the nodes labels, arrows that shows the sense from source to destination etc...

I want to do this using plotly dash to have an interactive plot, however, in the examples I have seen in plotly dash.networkx, they always have to declare the nodes and edges manually, which will require to have a for loop over the dataframe to pass all the entries of the dataframe. In my case, I have a pretty large dataframe which will be a problem.

My question is that, is there a way that I am missing, to create the graph using dash in a simple way without the need to declare the edges and the nodes manually? a way similar to that line of code?

Graph = nx.from_pandas_edgelist(rules,source='source',target='target').

and if there is a way, can I access the nodes by their ids? and how to insert nodes labels in the graph.

Thank you in advance.

I have tries visdcc and cytoscape libraries using plotly dash. In visdcc I used a loop which took a lot of time to pass through the dataframe entries. And in cytoscape, it needs to create the nodes and edges manually, which I do not want to do, my question is, if there is a way to create the graph automatically using the dataframe as.networkx and the draw option do.

Yes, it is possible to use a dataframe to create a.network graph with Networkx and then render this.network graph in Dash-Cytoscape (you don't have to enter nodes and edges manually). In the question I asked yesterday ( here ), you can find a code example to achieve this (my question was about something more specific).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM