Skip to content

Instantly share code, notes, and snippets.

@jeroen
Created April 1, 2023 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroen/a7b1de85f9de9478e1eb43dd629b46b0 to your computer and use it in GitHub Desktop.
Save jeroen/a7b1de85f9de9478e1eb43dd629b46b0 to your computer and use it in GitHub Desktop.
webr export csv file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World! Site Title</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js"></script>
<script>
import('https://webr.r-wasm.org/latest/webr.mjs').then(function(x){
const webR = new x.WebR();
return webR.init().then(function(){
return webR.evalR('write.csv(iris, "iris.csv")').then(function(result){
return webR.FS.readFile("iris.csv").then(function(bytes){
var blob = new Blob([bytes], {type: "text/csv"});
return saveAs(blob, "iris.csv");
});
});
});
}
).catch(function(err){
alert("ERROR: " + err);
});
</script>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment