Alceu,

I agree that a client side API makes sense in this case.  Solves the
whole question of temp files.  You may want to look into the
Google Chart API.  It's a REST service, where you pass the data
to be graphed, the style of graph desired (line, bar, pie, 3D pie,
Venn, Scatter, Radar, Geographic map, Speedometer, etc.), and
lots of other optional attributes, as URL params and it returns
you a PNG file of the graph.  So you simply put URLs in your web
page, and the browser collects and displays the graphs.  Very
easy to use!

See my quick summary of it, with lots of dynamically generated
examples, here:
- http://bristle.com/Tips/Internet.htm#google_chart_api

--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 5/23/17 11:40 AM, Alceu Rodrigues de Freitas Junior wrote:

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...@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.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c95a5ccb-37c6-53ee-26a3-9296265ee371%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/547bb719-bc4f-2f1f-fbda-e28bc8199c32%40bristle.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to