I want to directly use the script tag like this to use FileAttachment in local project.
<script src="https://unpkg.com/@observablehq/stdlib@3"></script>
Does this make sense, and if so, can I convert the file data into variables, out of the scope constraints of the file request?
var t;
d3.csv('test.csv', function(data) {t = data;})
console.log(t); // undefine
My ideal usage would be something like this.
var data = d3.csvParse(await FileAttachment("myFile.csv").text())
console.log(data);
radames
September 27, 2020, 9:48pm
2
Hi @HazardTrigger , FileAttachment if a server feature on Observable, I guess if you want to access local files using Observable stlib you can look at this way to do it
As an alternative to attaching a file to your notebook, you can read files from your local file system in Observable using a file input: The initial value of a file input is undefined, so any cell that references this file will wait for the reader to...
essentially you would craft your notebook code on Observable, export the code, run it locally and then load your data using the UI. As you might know accessing the file system is not something allowed through browsers, and you can read more about this here
Unfortunately this looks like it won’t be possible based on the security design of this feature:
The API will deny requests for user decisions coming from 3rd-party frames.
You could petition the browser vendors to add support for this. Alternatively, it might be possible for Observable to pass-through access to native files in the future, like we’ve done for FileAttachment.
In the meantime here’s another way to read local files:
@radames Thank you very much for your answer, this question has really been bothering me for a long time!
1 Like