jupyter_anywidget_graphviz
Jupyter anywidget for rendering diagrams from .dot language to SVG using Graphviz Wasm (hpcc-systems/hpcc-js-wasm).
Install as:
pip install jupyter_anywidget_graphviz
Usage
This runs in a browser based Jupyter environment and uses the browser machinery to run the wasm application.
# Import package
from jupyter_anywidget_graphviz import graphviz_headless, graphviz_panel, graphviz_inline
# Create a headless widget
# - works in: Jupyter Lab, Jupyter Notebook, VS Code
g = graphviz_headless()
# Inline mode
# Preview output as cell output from initialising cell
# - works in: Jupyter Lab, Jupyter Notebook, VS Code
# g = graphviz_inline()
# Create a widget panel with a handle
# - uses jupyter sidecar (Jupyter Lab only)
#g = graphviz_panel()
# Load magic
%load_ext jupyter_anywidget_graphviz
We can now write dot code in a magicked code cell (%%graphviz_magic WIDGET_HANDLE):
%%graphviz_magic -w g
strict graph {
a -- b
a -- b
b -- a [color=blue]
}
The -w / --widget-name setting can be used to set the widget within the magic and it does not need to be passed again.
Use the -e / --embed flag or the -t / --timeout TIMEOUT_IN_S switch to render the output SVG as cell output (not JupyterLite / marimo).
The widget can also be set via line magic: %setwidget g
The output is previewed in the UI panel, if rendered.
Retrieve the SVG diagram as WIDGET_HANDLE.svg.
We can also display the diagram manually in the notebook e.g. as:
from IPython.display import SVG
SVG(g.svg)
In its base form, the way the Jupyter event loop runs means we can't directly generate an output from the magic cell. However, setting the -e/--embed flag, or setting a timeout -t/--timeout SECONDS (default 5s), we can force a blocking action on the cell that waits for the asynchronous graphviz object to return the generated SVG, and then render it.
The .blocking_reply() method on the object will also block until the response status is set to completed.
If you set g.audio = True, error messages will be spoken alound using browser text to speech.
Alternative solutions
viz.js [repo] also seems to offer in browser graphviz rendering. KrunkZhou/jupyterlab-viz-krunk is a JupyterLab extension (untested) that seems to support backticked ```graphviz blocks in markdown cells.
Here'a an alternative anywidget using the same graphviz wasm package from @basnijholt: https://github.com/pipefunc/graphviz-anywidget
Other (predominantly, ouseful) sideloading wasm anywidgets
See the GitHup topc tag: jupyter-wasm-anywidget-extension
Metadata
Release files for jupyter-anywidget-graphviz 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jupyter_anywidget_graphviz-0.1.8.tar.gz | 587.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jupyter_anywidget_graphviz-0.1.8-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 1.2 MB
Release files / jupyter_anywidget_graphviz-0.1.8.tar.gz
| Download URL | jupyter_anywidget_graphviz-0.1.8.tar.gz |
|---|---|
| Size | 587.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f08e29c0105c1be1e9e54eb25863b08bbb1f1c999ef55c915f03d48e532c396e
|
|
BLAKE2b-256 checksum How to use checksums |
5c92f5915926a0f05b79481b23843e733ec08f9c573d11fd0717a654c59414d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.0
|
Release files / jupyter_anywidget_graphviz-0.1.8-py2.py3-none-any.whl
| Download URL | jupyter_anywidget_graphviz-0.1.8-py2.py3-none-any.whl |
|---|---|
| Size | 589.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
1a1998c9f2ef8a11da0adcca54ad3aed37a291e7066386babce62052999c2297
|
|
BLAKE2b-256 checksum How to use checksums |
2386a81088ab2faab4341fd11a64bd229e11bc2e918ebb4d99293de70b824b9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.0
|