19

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://)?

1
  • 4
    Firefox works fine with local filesystem. IE and Chrome do not, and the other answers have pointed out how to deal with those. Commented Mar 14, 2013 at 20:02

4 Answers 4

30

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

Sign up to request clarification or add additional context in comments.

2 Comments

Note: This command starts the Python web server in the background. To stop the server, type fg (to bring the process into the "foreground"), then press Ctrl+C. More info: digitalocean.com/community/tutorials/…
For Jetbrain users, right click on html file and click "Run '{filename}'" button and you are good to go :)
9

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://.

Comments

3

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.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.