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.

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


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.6.tar.gz (587.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jupyter_anywidget_graphviz-0.1.6-py2.py3-none-any.whl (589.3 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for jupyter_anywidget_graphviz-0.1.6.tar.gz
Algorithm Hash digest
SHA256 9d9ac15b2a42c18d1173b98f0fd9ac7a278bd5757ff82a4b195454998171b07d
MD5 7aca5288d054523109e7cc4972b8b26f
BLAKE2b-256 61aaa91edcd496e23bf7123939de4d533813eab65c025a0778de089b49d5eb1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jupyter_anywidget_graphviz-0.1.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 671f2a28c4e9c7ea81d4986814c778360608cf602c5a1c13c4473f84b4a9c531
MD5 efeb9cbc0c0242a937487687e191ae12
BLAKE2b-256 a40c941ffea611cdb09f500cd9ec239183f49d5578aff79b2869d8b48b86bd0b

See more details on using hashes here.

Supported by

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