1

I wonder what is the best way to serve a pyvis network with FastAPI?

enter image description here

This iteractive graph was generated with pyvis and is stored in an html file and then displayed as an interactive tool in JupyterLab. I would like to serve it as part of a molecular graph exploration tool. I wonder what is the best way to do so?

import networkx
import obonet

G = obonet.read_obo('https://ftp.ebi.ac.uk/pub/databases/chebi/ontology/chebi_core.obo')

# Create smaller subgraph
H = nx.ego_graph(G, 'CHEBI:17710', 2)

H.nodes['CHEBI:24669']

from pyvis.network import Network

nt = Network('1500px', '1500px', notebook=True)
nt.from_nx(H)
nt.show('H.html')

1 Answer 1

1

First thought is to serve the template using the type HTMLResponse. Just return it as is. But you may need more work to render it well. So...

Second thought, make a template with a Jinja2 base and include your content in a block, so you can take care of any set up work necessary for the display.

See more at this response, where some code is already written that I would write anyway.

Very interested in your result.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the inspiration!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.