-2

I have a python script that produce a figure (with matplotlib) with data from .txt files.

My goal is to run the python script from an HTML code and print the figure on a website. That way, I could just update the .txt files on the website and have a figure always up to date with the data.

I saw Flask and Django that make applications, but I already have my HTML made, so I just want a way to simply include a "run python script" somewhere in my HTML code. I saw web.py or Python CGI programming but I'm not sure if I can do what I want.

Is there another way to acheive that from a python package or should I really start a Django/Flask app? Should I have another approach?

  • What is your webhost situation? Shared server with someone like NameCheap? VPS with a webhost? Enterprise? And is it a Windows stack or a LAMP stack? – cssyphus Jun 20 '19 at 18:10
  • HTML works on the client, while your Python script will be executed on the server. If the _server_ doesn't know how to execute it, the HTML webpage won't be able to do anything either because it's just the frontend – ForceBru Jun 20 '19 at 18:11
  • My website is hosted with webhostapp, its free and I can upload up to 1GB. My data files sizes are ~0.1MB. – Jérémy Talbot-Pâquet Jun 20 '19 at 18:18

1 Answers1

2

If you really need to run your Python in the browser then take a look at Brython.

It is a JavaScript library that allows you to load and run Python 3 in the browser:

https://brython.info/

Intervalia
  • 10,248
  • 2
  • 30
  • 60
  • Thanks, I'll take a look into it, seems like what I was searching for! – Jérémy Talbot-Pâquet Jun 20 '19 at 18:21
  • Brython might not be the correct answer for the OP, as [it appears to run entirely client-side](https://stackoverflow.com/questions/14418774/is-brython-entirely-client-side), requiring each visitor to the website to have Python installed on their local machine in order to see the updated matplotlib figure...? – cssyphus Jun 20 '19 at 19:19
  • No need for the clients to have Python. Brython is an in-browser Python interpreter. – Intervalia Jun 20 '19 at 19:37