0

I am trying to figure out how to use flask to just show a simple image and update with a new image. I have the following that seems to work just fine for images (pretty much right from MPL website):

@app.route("/image")
def show_image():
   to_show = do_stuff(os.listdir( current_dir )[-1] ) #turn file into 2d np.array
   fig, ax = plt.subplots()
   ax.imshow( to_show, **plot_pars)
   buf = BytesIO()
   fig.savefig(buf, format = "png")
   plot_url = base64.b64encode(buf.getvalue().decode("utf8")
   return render_template("index.html", plot_url = plot_url)

The index.html file is currently setup to refresh every 15 seconds

<!DOCTYPE html>
<html>
    <head>
        <title> Plot</title>
        <meta http-equiv='refresh' content="15>
    </head>
    <body>
        <img src="data:image/png;base64, {{ plot_url }}">
    </body>
</html>

I am curious if I can set something up that will basically run show_image if the length of my current_dir changes. If I try it in my show_image function (if os.listdir( current_dir) != nfiles ), but nothing changes, so I am trying to figure out the best way to start with this "trigger".

yankeefan11
  • 485
  • 1
  • 6
  • 18

0 Answers0