How to run d3js at server-side in a Python web application (Heroku)?

In my web application, the user is able to draw some objects. The drawing functionality is implemented (at client-side) using d3js (SVG). The attributes of the objects (shape, coordinates, colours) are saved at server-side in a structured database.

Now, I need to render the drawings at server-side as well. I would like to reuse (at server-side) the rendering logic implemented at client-side. That is, to obtain a SVG (then convert it to PNG / PDF), given the object attributes saved in the database.

I see (at least) the following options:

  • install NodeJS on Heroku as well, and execute node from my Python web application. This would require JSDOM if I understood well - see this;
  • use to open a local HTML file that does the actual rendering (using d3js);
  • send the rendered SVG from client-side to the back-end - this is a poor choice, though.

What is your recommendation?

Thank you!

1 answer

  • answered 2017-06-17 19:03 Daniel Jamrozik

    I wouldn't recommend the third option because going back and forth from client to server can cause issues, and best to avoid it.

    The first option would work, but then you have a whole framework for one specific problem.

    I like the second option, using, because it's conceptually easy to understand, and very lightly couples with other parts of the codebase, which is always a goal in well written projects.

    You can also use phantomJS to run this (or something like it), which is the same kind of approach as, but straight to the javascript.