1

I have seen many separate answers and they just seem difficult to follow. I'm hoping someone can give me a simple explanation or at least show me a simple tutorial.

My objective is to build a web page (just on my machine for now) that will have three things: A title, a series of 5-10 dropdown menus/buttons, and a Matplotlib Plot (generated from python code). I want to be able to browse this page:

<html>
<head>
<title>My Example Web Page</title>
</head>
<body bgcolor="#ccffcc">

<form action="my .py file that I want to run when user presses submit" method="post" target="_blank">
<select name="dropdown">
<option value="Opt1" selected>Opt1</option>
<option value="Opt2">Opt2</option>
</select>
<input type="submit" value="Submit"/>
</form>

<p align="center"><img src="MY MATPLOTLIB IMAGE WOULD GO HERE???" width="100" height="100">

</body>
</html>

As seen above, I have the heading no problem. I have one dropdown box -- but when I push submit -- nothing happens. I point to "C:\Python27\myfile.py" but nothing seems to happen. I want to take in the dropdown info (which option was selected), run my code, and then return a MATPLOTLIB plot to the page. I don't understand how to do these two steps. Does anyone have any advice?

Again:

  1. Receive information from user "submit" form
  2. Run the .py file on "submit"
  3. Plot resulting plot on the webpage in the appropriate spot.

FYI - I am not bad with Python programming but have never done HTML (or other web languages).

Thanks!

mcfly
  • 1,151
  • 4
  • 33
  • 55
  • I would recommend trying out the web framework flask (http://flask.pocoo.org/), and maybe seeing this answer for a good starting point: http://stackoverflow.com/questions/20107414/passing-a-matplotlib-figure-to-html-flask – colcarroll Feb 10 '14 at 04:21
  • @JLLagrange I agree with JLLagrange. I think bottlepy is even simpler than flask (one-file), and there is a matplotlib bottlepy widget ready to use here: https://github.com/mmarquar/bottle-matplotlib/blob/master/bottle_matplotlib.py – Yuxiang Wang Feb 10 '14 at 05:45
  • Is there a comprehensive example you know of using flask where I can either select an item or press button, my python code is triggered, and then an image is sent to the html page to replace/update the previous image (without refreshing the page)? – mcfly Feb 11 '14 at 16:15

0 Answers0