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!

3
  • I would recommend trying out the web framework flask (flask.pocoo.org), and maybe seeing this answer for a good starting point: stackoverflow.com/questions/20107414/… Commented Feb 10, 2014 at 4: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: github.com/mmarquar/bottle-matplotlib/blob/master/… Commented Feb 10, 2014 at 5: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)? Commented Feb 11, 2014 at 16:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.