Issue with saving graphviz dot file as png to anvil table

What I’m trying to do:
I am trying to create a small graph using Graphviz and save it to an anvil table row. I tested the png creation code (i.e. first 4 lines), it works in colab as expected

def create_graph():
  g = Digraph('G')
  g.edge('Hello', 'World')
  graph = pydotplus.graph_from_dot_data(g.source)  
  graph.write_png('/tmp/mygraph.png')
  new_file = anvil.media.from_file("/tmp/mygraph.png", "image/png", "myfile.png")
  app_tables.table_5.add_row(file=new_file, filename="myfile.png")

What I’ve tried and what’s not working:

I have added graphviz and pydotplus packages, I am running into the following error

Starting server runtime… Server runtime connected.

InvocationException: GraphViz's executables not found

  • at /home/anvil/.env/lib/python3.10/site-packages/pydotplus/graphviz.py:1959
  • called from /home/anvil/.env/lib/python3.10/site-packages/pydotplus/graphviz.py:1918
  • called from /home/anvil/.env/lib/python3.10/site-packages/pydotplus/graphviz.py:1810

Greatly appreciate any pointers

Hi @ananth,

You need to have GraphViz installed on your server (not just the python package but an executable installation). I don’t think you can do this on an Anvil server, so you must install this on a server that you connect to Anvil via uplink.

Cheers,
Stein

wow. Just copied the function over as an uplink function to colab and worked with no change. Thank you @stein