Is it possible to use graphviz directly from its source code, instead of installing it?

1.8k Views Asked by At

I have built a simple module in python that generates some graphs using graphviz, by calling dot directly as a shell command. I had planned to put this module online on my website. However, in order to use graphviz (and dot), it has to be installed on the computer that is calling the script, and unfortunately the company I host my website with will not install it on their server.

I was trying to think of alternatives so I could still put the module online. I had read that there was a graphviz API that could be called to generate the graphs, but the site with info about it was down.

Then I had a thought - since graphviz is open source and the source code is available online, is it possible for me to somehow copy all the source code in to my homedir, and do something to get graphviz to work without going through a formal installation process? I'm not certain actually what takes place during the installation - and it made me wonder if those installation processes are something I myself can do manually? (I didn't know if it came down to copying files in the right place, setting environment variables, etc. And similarly, it would not be a problem for me to change my code, to call the absolute path of 'dot.exe', or things like that.) Does anyone know where I might learn about this? Or alternatively, if this is something which is not possible - to let me know?

I appreciate any help or suggestions you might provide. (P.S. I am aware of google's charts API but it is not suitable for what I am doing.)

2

There are 2 best solutions below

1
On BEST ANSWER

You can't use Graphviz directly from its source, since it's written in C and needs to be compiled.

However, you can use d3-graphviz, which uses Viz.js which is Graphviz ported to Javascript. Here is how you generate your example graph from a fixed string.

<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="//d3js.org/d3.v4.min.js"></script>
<script src="https://unpkg.com/[email protected]/viz.js"></script>
<script src="https://unpkg.com/[email protected]/build/d3-graphviz.min.js"></script>
<div id="graph" style="text-align: center;"></div>
<script>

d3.select("#graph").graphviz()
    .renderDot('digraph{A -> B -> C-> A}');

</script>

If you put your python module online and let it output the DOT source, you should be able to write some Javascript code to load it and use d3-graphviz to render the graph.

1
On

In case anyone sees this in the future, it seems the old version of Google Charts has a deprecated API for creating graphviz graphs, which still works, and it seems to create the same graphs you can create if you have graphviz installed locally. It works for my purpose so perhaps it will help someone else.

To use it, simply create the following URL, where you supply the graphviz specification of the graph you'd like to generate, as the chl param:

https://chart.googleapis.com/chart?cht=gv&chl=<your graph string here>

example:

Here is the specification of a simple graph in graphviz:

digraph{A->B->C->A}

I can create this graph using the api, by specifying that exact string as the chl param in the URL, as seen below. Click on the link - and see the graph!

https://chart.googleapis.com/chart?cht=gv&chl=digraph{A->B->C->A}

Here is a link that helps describe!

https://developers.google.com/chart/image/docs/gallery/graphviz