No project description provided
Project description
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.
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jupyter_anywidget_graphviz-0.1.5.tar.gz.
File metadata
- Download URL: jupyter_anywidget_graphviz-0.1.5.tar.gz
- Upload date:
- Size: 586.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db0f860a19eeeb4dc6b7e1cdb646329a17a4d7dc830f92e8842eae68d111c329
|
|
| MD5 |
32a4db2cff2177715c826a92d49ae1e9
|
|
| BLAKE2b-256 |
33ea2c118c811d4d4638936432756ff292ff93a8a0bce0af786a702355761a23
|
File details
Details for the file jupyter_anywidget_graphviz-0.1.5-py2.py3-none-any.whl.
File metadata
- Download URL: jupyter_anywidget_graphviz-0.1.5-py2.py3-none-any.whl
- Upload date:
- Size: 588.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e8c1bcb60c5523e04510ab96392c23cb6b5cd615e5ee2ba09e8bf6660b24545
|
|
| MD5 |
3f01d1ca44bd9fe9a53e0f01bdc33b18
|
|
| BLAKE2b-256 |
b5d122dbf36995aa1d46d627fe3f4d2d51251237f41e075171b9e0f76dc19afb
|