Reputation: 45214
I know that D3.js supports loading data files with XHR and JSONP requests.
However in my case, I am going to run .html files by double clicking on them from filesystem, which is going to run it like file://.../foo.html
on browser.
Is it possible to load data file (csv or json) within the same directory from computer as foo.html
on browser (while not running on http://
but file://
)?
Upvotes: 19
Views: 20831
Reputation: 31
Adding onto Christopher Chiche's answer (I am a new user, can't comment). For python 3 in Windows, that command does not work. Instead use this one
python -m http.server [<portNo>]
As described here, in python 3
the module SimpleHTTPServer has been replaced by http.server, at least in Windows.
Upvotes: 3
Reputation: 401
Similar to the python answer from Christopher Chiche above, you can also use the built-in server that comes with various versions of PHP.
php -S localhost:8888 &
This was more useful for me, as my application has hooks to a php back-end script as well as the d3 front-end.
Upvotes: 2
Reputation: 15335
The best solution would be to run a server on your computer to make it work.
The simplest way to have a local web server, as explained here is to run this command in the directory where you have your source code:
python -m SimpleHTTPServer 8888 &
Then just load the page http://localhost:8888
Upvotes: 30
Reputation: 109232
You can by disabling the respective security mechanisms in your browser. I think it works in Opera by default, and you can start Chrome with the --allow-file-access-from-files
command line flag to allow loading data from file://
.
Upvotes: 9