fully working csv download
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
function saveCsv(csvStr) {
|
||||
function saveData(csvStr, filename) {
|
||||
// string rep
|
||||
// var csvStr = "";
|
||||
// for (let r = 0; r < csvData.length; r++) {
|
||||
@@ -17,5 +17,12 @@ function saveCsv(csvStr) {
|
||||
var data = new Blob([csvStr]);
|
||||
|
||||
// create & click temp link
|
||||
window.open(URL.createObjectURL(data));
|
||||
// slightly modded https://stackoverflow.com/a/15832662
|
||||
var link = document.createElement("a");
|
||||
link.download = filename;
|
||||
link.href = URL.createObjectURL(data);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
delete link;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
<strong>Temperature Distribution</strong>
|
||||
<button
|
||||
style="width: 10rem; height: 2rem; margin-left: 1rem;"
|
||||
download="temperature-data.csv" type="text/csv" onclick="saveCsv(`{{csv_data}}`)">Download Data as CSV</button>
|
||||
onclick="saveData(`{{csv_data}}`, 'temperature-data.csv')">Download Data as CSV</button>
|
||||
</div>
|
||||
{{ freq_plot | safe }}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user