Charts in django Web Applications - python

I want to Embed a chart in a Web Application developed using django.
I have come across Google charts API, ReportLab, PyChart, MatPlotLib and ChartDirector
I want to do it in the server side rather than send the AJAX request to Google chart APIs, as I also want to embed the chart into the PDF.
Which is the best option to use, and what are the relative merits and demerits of one over the other.

Another choice is CairoPlot.
We picked matplotlib over the others for some serious graphing inside one of our django apps, primarily because it was the only one that gave us exactly the kind of control we needed.
Performance generating PNG's was fine for us but... it was a highly specialized app with less than 10 logins a day.

Well, I'm involved in an open source project, Djime, that uses OpenFlashChart 2.
As you can see from our code, generating the JSON-data that OFC uses is a bit complex, but the output is very nice and user friendly, since you can add tooltips, etc. to the different elements.

Open Flash Chart 2
http://teethgrinder.co.uk/open-flash-chart-2/
python library http://btbytes.github.com/pyofc2/
kybi

One package I've wanted to try is graphite. It's a graphing server / platform built with Django. It's specialized for "numeric time-series data" though, like stock prices or bandwidth utilization. If that fits your need I would check it out. Here are some screenshots:
http://graphite.wikidot.com/screen-shots

I like client side charts because you can get full page plotting.
A good options seems to be Jquery Flot : http://code.google.com/p/flot/ which can load JSON data.
However, you won't get pdf support.

Perhaps you might want to have a look here: Django Plotting app.
The HowTo describes how to embed matplotlib plots into the admin interface and create a PDF view.

I have used FusionCharts Free with Django.
Its flash based, open source, multi-licensed and it's well documented. It's ActionScript 1, but AS version wasn't really a criteria for me, though it could be for others.

Related

How to Embed a Plotly Interactive Graph in Webpage

I have an interactive graph generated by Plotly in Python that I saved to an html file using plotly.offline.plot(fig, filename='/tmp/interactiveGraph.html')
I am now trying to embed this interactive graph into some kind of webpage, using either Dash or Django. I'm leaning toward Django at the moment, given that I have an html version of the graph. Which would be better?
My code for the webpage is in a separate file from the code where I am creating the graph.
A lot of the tutorials I've found online just say to add a few lines to the template, but I don't know how to get those lines that they've described.
tl;dr: I'm looking for guidance as how to integrate an html file-for a Plotly interactive graph-with a web python script using Django or Dash
Side Question:
what is the difference between
plotly.offline.plot(fig, include_plotlyjs=False, output_type='div')
and what I have above?
Reference:
https://github.com/ricleal/DjangoPlotLy
https://www.pythonsetup.com/how-implement-data-visualization-django-and-plotly/
I would highly reccomend Django, its a great framework. As for this, the best option is to generate the data via JavaScript and Plotly has a great library for this. If you must use python, then Django can be used. Assuming you are familiar with Django, inside of your view you can collect your data and build your graph ( I would reccomend a celery task for something long running like this unless they are small graphs), and you can then collect the return from creating the graph in div format. This will return a string that holds all the needed html and css for the graphs. Put this inside of you get_context_data() method in your view and place it into the dictionary. You can the use that object inside of a template. I have done this before, if you are having a hard time feel free to DM me. Hope this helps some!
In regards to your side question, I believe having False for including JS will make the graph a bit smaller assuming you have an include for the plotly JS library. They might have done this in a newer release to make the graphs faster as they were significantly slower in the browser from python that the JS rendered one.

Django / Geodjango / Raster / geotiff: Problems with practice task

I got a practice task, which I can not get any further.
The task is the following:
Project Description The goal of the projects is to create a map view
similar to the Google Maps, where the user can see some imagery data
captured by drones.
User should be able to move around the map freely, as well as zoom in
and zoom out to take a closer look at the captured imagery data.
It is strongly desired that the served imagery data will support
transparency while minimizing the file size and bandwidth usage. This
does not have to be implemented, but solution ideas are welcomed.
The raw imagery data will be provided as GeoTIFF files. Imagery
visible on the map can be added by placing a file inside a directory
that is read by the server. Project Delivery Method
Project should be delivered as a Git repository with documentation
required to setup and run the project.
Requirements
1. Server implementation in Python 3.5+
2. Project must be able to run on Ubuntu Server 16.04
3. Optimal disk space usage for imagery data displayed to the user (as the app may be processing terabytes of satellite imagery data)
4. Relatively conservative bandwidth usage
Notes:
1. The project will be deployed on a machine that is already running other Python software. Dependency conflicts must be avoided.
(virtualenv, Docker)
2. The UI can be a simple HTML page with embedded libraries and inline scripts.
In addition, it was specified in an e-mail:
"The test task is not code but just the approach and rough app
architecture
```I'm attaching a tank spec. Like I've mentioned. I'm more interested
in problem-solving and your ideas. I expect a working prototype tough.
Use any libraries you wish to use. Create an elegant, easy to
understand the solution. You can use as much time as you want. Would be
great if you could deliver the code by git.... ```"
So far I have done:
Ubuntu as VM
Venv
Postgres and PostGIS installed (Django writes error-free in a database)
Django project and app created
Documentation up to this point
I have now integrated the geotiff via console and that seems to work too:
from django.contrib.gis.gdal import GDALRaster
raster = GDALRaster('base/static/base/geotiff/xto-site3-rgb.tif')
raster.name
Out[4]: 'base/static/base/geotiff/xto-site3-rgb.tif'
raster.width, raster.height
Out[5]: (23001, 9668)
In the models.py is so far:
from django.contrib.gis.db import models
class RasterBase(models.Model):
raster = models.RasterField()
name = models.TextField()
How does it work that I install the grid so that I can portray this in an html similar to google maps? If I understand correctly, I must now write the geotiff in the database, and read on from there, right?
Unfortunately, I find in the network largely only outdated stuff, or often examples, which is assumed by shapefiles. Should I convert the grid to a shapefile and continue like that?
So far, I only make small things in Django, like my own blog and a few statistics, but this with Geodjango is a bit fierce because I have to give it up, as it were tomorrow. Latest Tuesday morning.
I would be very grateful if someone could give me some tips. All in all, that's pretty important to me, and it would be a shame if I messed up half of the task (or the last third) of the task.
Django is version 2.0
The GeoTIFF ~900mb
Thanks for all. :-)
Late to the party, but maybe some people are searching for a solution here.
When you want to display geodata on a map, you can use a WebGIS framework like Openlayers or Leaflet. They provide all the functionality to move the map and zoom in / out.
I would not recommend to store large raster data in a database. You can serve it directly from a file server via a TileLayer or use a XYZ tiling structure to minimize the bandwidth usage.
Openlayers has a lot of examples on how to server GeoTiff files.

Generate dynamic plots with python

I am working on generating some plots using python, but I am generating these plots using matplotlib which is saved as images. If I create an html page as a report with these plots, they are static images. I cannot zoom in or roll over on the plot to see more detailed or specific information on a time series plot.
My question is how can I make these plots dynamic? Can someone suggest the best way to get started and move forward from there?
You should use some additional libraries to achive your goal.
For example, there some good Python web frameworks wich you can use:
CherryPy - allows you to simply write web-app with Python and you can import your plot there.
Plotly Python API - it would simply generate interactive plot, but store it at Plotly platform, but they provide embeded-code option, so you can use it on your site.
I would suggest Plotly, because it is much simpler, but it depends on your needs.
You will definitely want to do it using javascript. It's by far your best option when it comes to quickly make interactive graphs that you can present to a lot of users. Any of these js libraries will do a great job.
You will then want python to provide the data. Depending on the js library you are using, you might be able to parse data from .json, .csv, etc...
If you don't need the data that makes up your plots to change (with user input, for example), then generating and saving flat files with python and having javascript parsing them from some directory might be just enough.
Otherwise, you want to take a look at a python web framework and use one as backend to serve the plots data by request (in that case .json is probably the right format).
Frameworks like Flask, CherryPy, Pyramid or even web2py might be the easier ones to start with.

Use Python CGI or Django for a web project

I am a front-end web developer learning Python and decided to try to create a website for a friend. The website contains an astrology calculator that will generate a chart image and reading based on a person's birth date, birth time, and birthplace. I can use either Python CGI or Django to build this. Which one is appropriate for this project?
The chart calculator will:
1. generate an image of a chart with the correct houses and signs lined up.
2. plot the planets in the correct houses in the chart
3. show the connections between the stars, like a trine, square, or conjuction.
To render images, I think HTML5 can probably work. For the server-side scripting I am leaning towards CGI because it seems like you can write real Python programs with it and just output the results with something like print "sun conjunct jupiter". Django seems to limit you to that weird syntax that forces you to write every Python expression in these <% ... %> brackets and it doesn't seem like you can import Python modules easily.
I am not extremely familiar with Django, but these seem to be some of the limitations I noticed in the Django tutorial.
What do others in the community think? Should I use CGI or Django to create this website?
I checked out other questions, but not sure if a Python mini-framework is appropriate here.
Not really sure what you're hoping to glean from this (or what the question is exactly), but you seem to be misinterpreting what the Python CGI functions and Django are.
Django is a web framework meant to expedite the process of developing a website, so you can focus on specific issues (like the chart problem you described) rather than have to tend to the infrastructure of a site. It's meant to abstract away CGI (to oversimplify it a bit). If you're looking for something less heavy than Django, perhaps try Flask or Bottle.
PS: A quick Google search showed a similar question from a few years back: My first web app (Python): use CGI, or a framework like Django?

How to display database query results of 100,000 rows or more with HTML?

We're rewriting a website used by one of our clients. The user traffic on it is very low, less than 100 unique visitors a week. It's basically just a nice interface to their data in our databases. It allows them to query and filter on different sets of data of theirs.
We're rewriting the site in Python, re-using the same Oracle database that the data is currently on. The current version is written in an old, old version of Coldfusion. One of the things that Coldfusion does well though is displays tons of database records on a single page. It's capable of displaying hundreds of thousands of rows at once without crashing the browser. It uses a Java applet, and it looks like the contents of the rows are perhaps compressed and passed in through the HTML or something. There is a large block of data in the HTML but it's not displayed - it's just rendered by the Java applet.
I've tried several JavaScript solutions but they all hinge on the fact that the data will be present in an HTML table or something along those lines. This causes browsers to freeze and run out of memory.
Does anyone know of any solutions to this situation? Our client loves the ability to scroll through all of this data without clicking a "next page" link.
I have done just what you are describing using the following (which works very well):
jQuery Datatables
It enables you to do 'fetch as you scroll' pagination, so you can disable the pagination arrows in favor of a 'forever' scroll.
Give a try with Jquery scroll.
Instead of image scroll , you need to have data scroll.
You should poulate data in the divs , instead of images.
http://www.smoothdivscroll.com/#quickdemo
It should work. I wish.
You gotta great client anyway :-)
Something related to your Q
http://www.9lessons.info/2009/07/load-data-while-scroll-with-jquery-php.html
http://api.jquery.com/scroll/
I'm using Open Rico's LiveGrid in a project to display a table with thousands of rows in a page as an endless scrolling table. It has been working really fine so far. The table requests data on demand when you scroll through the rows. The parameters are send as simple GET parameters and the response you have to create on the serverside is simple XML. It should be possible to implement a data backend for a Rico LiveGrid in Python.
Most people, in this case, would use a framework. The best documented and most popular framework in Python is Django. It has good database support (including Oracle), and you'll have the easiest time getting help using it since there's such an active Django community.
You can try some other frameworks, but if you're tied to Python I'd recommend Django.
Of course, Jython (if it's an option), would make your job very easy. You could take the existing Java framework you have and just use Jython to build a frontend (and continue to use your Java applet and Java classes and Java server).
The memory problem is an interesting one; I'd be curious to see what you come up with.
Have you tried jqGrid? It can be buggy at times, but overall it's one of the better JavaScript grids. It's fairly efficient in dealing with large datasets. It also has a feature whereby the grid retrieves data asynchronously in chunks, but still allows continuous scrolling. It just asks for more data as the user scrolls down to it.
I did something like this a while ago and successfully implemented YUI's data table combined with Django
http://developer.yahoo.com/yui/datatable/
This gives you column sorting, pagination, scrolling and so on. It also allows you to use a variety of data sources such as JSON or XML.

Categories

Resources