12

I'm currently working on a project that involves parsing through a user-supplied file, doing computations with that data, and visualizing the results using graphing utilities. Right now, I'm stuck with using Python as the back-end because it has scientific libraries unavailable in JavaScript, but I want to move the entire tool to a web server, where I can do much slicker visualizations using D3.js.

The workflow would be something like: obtain the file contents from the browser, execute the Python script with the contents, return jsonified objects of computed values, and plot those objects using D3. I already have the back-end and front-end working by themselves, but want to know: How can I go about bridging the two? From what I've gathered, I need to do something along the lines of launching a server, sending AJAX requests to the server, and retrieving data from the server. But with the number of frameworks out there (Flask, cgi, apache, websockets, etc.), I'm not really sure where to start. This will likely only be a very simple web app with just a file submit page and a data visualization page. Any help is appreciated!

tomatoBisque
  • 153
  • 1
  • 1
  • 7
  • 2
    Primarily opinion-based questions are considered off topic for this forum. I am not sure you are really looking for an opinion about what framework is "best" but rather some direction to start working on a type of application which is new to you. If so, perhaps it is possible to reword it; I'm not sure. – Basya Aug 08 '17 at 21:24
  • 1
    Sorry for the confusion. I'm concerned with the latter. I'm aware each framework has its own pros/cons and it would be up to me to decide which is best geared for my project. I'm asking something even more basic: what would an integrated front/backend look like conceptually, using these frameworks as examples? – tomatoBisque Aug 08 '17 at 22:03

2 Answers2

11

Apache is a web server, flask is a web framework in python, websockets are a protocol, and cgi is something totally different, and none of them help you on the front end.

You could deploy a simple backend in flask or django or pylons or any other python web framework. I like django, but it may be a little heavy for your purpose, flask is a bit more lightweight. You deploy them to a server with a web server installed and use something like apache to distribute.

Then you need a front end and a way of delivering your front end. Flask / Django are both fully capable of doing so in conjunction with a web server, or you could use a static file server like Amazon S3.

On your front end, you need to load D3 and probably some kind of utility like jQuery to load and parse your data from the back end, then use D3 however you like to present it on screen.

bryan60
  • 28,215
  • 4
  • 48
  • 65
  • Very informative. Looks like I have a lot to learn! I'll keep all these things in mind along the way. – tomatoBisque Aug 09 '17 at 03:39
  • No problem. If you are in fact only serving static files, I recommend just dropping everything in an S3 bucket on AWS and configuring it as a web server. It is crazy easy to do, basically free, and there are countless tutorials. But it seems like you are not only serving static files. You need an application layer that accepts a file from the user and then transforms the data and sends it back to the front end, in that case you need something like flask or django, and an actual server instance somewhere to run it with a web server installed / configured. – bryan60 Aug 09 '17 at 16:08
7

Flask is easy to get up and running and is Python based. It works well with REST APIs and data sent by JSON (or JSON API).

This is one solution with which I have some experience and which seems to work well and is not hard to get up and running (and natural to work with Python). I can't tell you whether it is the best solution for your needs, but it should work.

If you are overwhelmed and don't know where to start, you can pick one of the options and google search for a tutorial. With a decent tutorial, you should have an example up and running by the end of the tutorial, and then you will know if you are comfortable working with it and have an idea whether it will meet your needs.

Then you could do a proof-of-concept; make a small app that just handles one small part (the one you are most concerned about handling, perhaps) and write something which will do it.

By then, you can be pretty sure you have a good tool for the purpose (unless you were convinced otherwise by the proof-of-concept -- in which case, try again with another option :-))

Basya
  • 1,477
  • 1
  • 12
  • 22
  • I'll give Flask another try! I actually looked into it before coming on here, but I saw many opinions saying that if you're only going to be serving static files (which I believe I am), then Flask is unnecessary. Thanks! – tomatoBisque Aug 09 '17 at 03:41
  • I missed the part about only static files. If it is only static files it could be you don't need it. We have more than that. But it was easy to bring up. I've worked with Apache but never brought it up from scratch. Apache is very reliable and stable web server, as far as I've seen, and is in use in so many places that it is a truly proven technology. My response was relating to the need to integrate with a Python backend (which sounds like more than static pages -- you have a backend processing stuff, not just html pages) – Basya Aug 09 '17 at 06:26
  • Technically, you could just use javascript, because as python supports the JSON API, sending a request can give back JSON, which JS is familiar with. – SuspenseFallback Jun 22 '21 at 03:16