Allowing users to download CSV on click

I got this to work on chrome, but for some reason it doesn’t work on Microsoft Edge. Has anyone had any luck getting it to work on Edge (or Safari, for that matter, which I haven’t checked yet?)

I also seem to be having a problem where files are being cached. When I update my code (so that the data is changed) and click the download CSV button, I get the old version of the file until I manually clear my browser’s cache. I’ve tried using Flask-Caching to clear this automatically:

cache = Cache(app.server, config={
‘CACHE_TYPE’: ‘simple’
})

cache.clear()

But it doesn’t seem to be working. I am storing the data in a hidden div to share between callbacks, but I don’t think that’s what’s being cached, because one of my code changes didn’t modify the hidden div data at all, just how the hidden div data was processed before writing to csv.

EDIT: I was able to fix the caching/not updating issue by using @carlottanegri and @chriddyp’s solution. However, it still doesn’t work on Edge.