Skip to main content

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

Example of graphviz anywidget

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.

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 display the diagram 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 canlt 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 gernerated 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyter_anywidget_graphviz-0.1.4.tar.gz (531.6 kB view details)

Uploaded Source

Built Distribution

jupyter_anywidget_graphviz-0.1.4-py2.py3-none-any.whl (533.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file jupyter_anywidget_graphviz-0.1.4.tar.gz.

File metadata

File hashes

Hashes for jupyter_anywidget_graphviz-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2fba3aebdaa00a08255c14445b105cfaeaa8f6ef4a6d77427fbb9b04b62132ff
MD5 97e8e39ac11f6f11a2195d272a8817bb
BLAKE2b-256 6a101cf6bb6b2bda768b7e91c7e2c22e9bb6d10c1814bed4e7d18477b54e98c1

See more details on using hashes here.

File details

Details for the file jupyter_anywidget_graphviz-0.1.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for jupyter_anywidget_graphviz-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5e3691c878141135952dcbd7fe86753a2e86733688a392d39c10a7e5a6edb28e
MD5 6ead977cad9854b1b006cc42f967c056
BLAKE2b-256 ffbe6e7e6ebd762345b382212aca54114c3c550a5b7532c40c612b2571746b9b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page