Tuesday, May 23, 2017

Re: best practices for handling charts

Thanks for answering James, I commented your e-mail below:


Em 23/05/2017 12:06, James Schneider escreveu:


On May 23, 2017 6:33 AM, "Alceu Rodrigues de Freitas Junior" <alceu.freitas.jr@gmail.com> wrote:
Hello to all,

I have some charts created with matplotlib and I would like to include them in my Django application.

What is the considered best practices in order to do that?

I'm considering processing the data and generating PNG files in "temporary" locations, so I when the chart file is created I just need to refer to it in the template.

This could create a problem because I would need to remove the chart file after a while, or even better, when the user logs out of the application. I did a quickly search in this group archive and couldn't find anything close related to this. It doesn't look simple to execute any kind of task when the user logs out (signals?) and there is a the risk of users just closing their browsers (which will require that I use crontab or something like it to delete old files).

Another possibility is to just open a new browser window and include in the response only the image itself.

Is there any better way to implement that?

Do you have any reason to keep the charts that are generated? You may be better off using JS to render the chart on the client side, then you don't have to worry about managing files. Maybe something like Flot charts? There's a ton of these libraries out there.



Well, besides having to learn a new API and not reusing the read-to-use code from matplotlib? :-)
Just kidding, it makes sense to use client-side for that and avoiding the temporary files problem completely but I really would like to reuse what is already implemented, unless it gives more trouble than using something like Flot.

No comments:

Post a Comment