cjdrake / gvmagic Goto Github PK
View Code? Open in Web Editor NEWGraphviz IPython magic commands
License: Apache License 2.0
Graphviz IPython magic commands
License: Apache License 2.0
Hi
I am running Jupyter Lab Version 1.2.4. I recently cranked up a Jupyter Notebook that was about two years old, and %%dot didn't work :( ( I got the broken object icon, instead of the rendered SVG).
I found the fix was to convert the dot
output (svg script) from a byte array to a string, like so in the function run_graphviz
:
dot = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
stdoutdata, stderrdata = dot.communicate(s.encode('utf-8'))
status = dot.wait()
if status == 0:
# convert byte array into string
return stdoutdata.decode('utf-8')
I guess iPython has become more strict in what it accepts (or has dropped support for Python 2.*)
happy to supply more info if needed
Don
I'm attaching two patch files for gvmagic.py, which you should be able to apply using git. They do the following:
dot
executable in the user's shell, and invoke it by absolute pathname. This addresses #1run_graphviz
returns a string. Under at least some conditions it will return a bytearray
instead of a string, and then jupyter won't properly display the SVG image.0001-Fix-invocation-of-dot-executable.patch.txt
0002-Ensure-run_graphviz-returns-string.patch.txt
Hi
I am running Jupyterlab Version 0.31.8 in Python 3.6 (3.6.3 | packaged by conda-forge | (default, Nov 4 2017, 10:10:42) [MSC v.1900 64 bit (AMD64)]), running on windows 10 (Windows-10-10.0.16299-SP0)
I installed graphviz 2.38.0 and python-graphviz 0.8.2 via anaconda navigator.
The dot shell command reports the dot version as:
dot - graphviz version 2.38.0 (20140413.2041)
I downloaded gvmagic.py from:
https://raw.githubusercontent.com/cjdrake/ipython-magic/master/gvmagic.py
on 7th March 2018
The magic commands:
%reload_ext gvmagic
%%dot
graph{
a -- b;
b -- c;
a -- c;
d -- c;
e -- c;
e -- a;
}
then fail with a Windows 'File not found' on the subprocess.Popen call that runs dot.
If I add the parameter shell=True to this call, then it all works fine:
IE dot = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
happy to run more tests, if needed
Cheers
Don
I am running Jupyterlab Version 0.31.8 in Python 3.6 (3.6.3 | packaged by conda-forge | (default, Nov 4 2017, 10:10:42) [MSC v.1900 64 bit (AMD64)]), running on windows 10 (Windows-10-10.0.16299-SP0)
I installed graphviz 2.38.0 and python-graphviz 0.8.2 via anaconda navigator.
The dot shell command reports the dot version as:
dot - graphviz version 2.38.0 (20140413.2041)
Jupyterlab is running in Microsoft Edge 41.16299.248.0
the simple %%dot file
%%dot
graph {
server1 [image="server.bmp", label="", shape=none]
server2
server1--server2
}
fails to display the image in the output cell, and converting the notebook to HTML also yields an empty node (with no image).
Running the equivalent dot command from the command line works fine (image is displayed in node).
The format of the image (bmp, png, etc) does not seem to affect the result (all fail to display inside the node in the diagram in the notebook output cell).
Please note that I am setting shell=True in the gvmagic Popen call, as per issue previously raised.
happy to run more tests
Don
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.