NetworkX Visualizations in Plone pages

What is the best approach to display a dynamically created networkx visualization in plone pages.

For instance I would like display networkx visualization (Mukhriz Mahathir โ€” Politikus) based on current page content ( person -> organization relationships).

Below is example networkx diagram created with pyvis. Thanks!

#!/usr/bin/env python3
# coding: utf-8

# # Basic NetworkX from Politikus API


import requests
import pandas as pd 
import networkx as nx
from pyvis.network import Network


session = requests.Session()
session.headers.update({'Accept': 'application/json'})
url = "https://politikus.sinarproject.org/@search?fullobjects=1&portal_type=Membership"

response = session.get(url)
result = response.json()


df = pd.json_normalize(result, 'items')


g = nx.Graph()
df1 = df[['person.title', 'organization.title']]
g = nx.from_pandas_edgelist(df1, 'person.title', 'organization.title')

nt = Network('500px', '500px')
nt.from_nx(g)

nt.show('nx.html')

Not trivial since show() generates a full HTML page and loads its on JS/CSS.

You could implement this special service outside Plone e.g. using FastAPI and include the rendered HTML from an IFRAME.

1 Like

I'd go with "write a browser view that generates a json", read it in a page template +js script that uses visjs (or anything like that) to display the network.

2 Likes

:+1: . We have written several other integrations based on this principle: for HighCharts and recently for bpmn.io. (Businesss process models). Store/generate/load the data on the backend as json, view it on the frontend with the available frontend (js) libraries.

If the frontend library also supports editing, create an extra 'save' view (or differentiate between GET/POST) to save the changed .json representation again to the Plone backend.

1 Like

I would have a look at collective.remoteproxy ยท PyPI plus some custom code.

There is a great deal of interest in graph-viewers as an alternative to site-maps, site navigation, and as another way of expressing the relationships (via Link objects or other custom objects) between objects within the ZODB. Graph visualization for navigation purposes is very powerful, particularly if it could be combined with something like a Collection object. I know that the prevailing idea within the community is that this is something that can (and should) be handled outside of Plone. However, I'm suggesting that incorporating graph navigation/visualization within Plone as a standard feature is a worthy idea. To me, this makes a great deal of sense precisely because the ZODB is a object database rather than a relational database. Just my $0.02.

We've been exploring the "graph vis as a browsing method" idea and settled on sankey as a saner way to show the relationship between documents, specially if the target is casual users.

Plone Foundation Code of Conduct