The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

405748 (5) [Avatar] Offline
Say I have the cities.csv file and my html / d3 file in a folder. What do I use as a d3 statement to find that file and read it?

I was trying to use the file path.

The web inspector message is that "cities.csv" isn't found and that this method of referencing is only supported for html. What is the right syntax to access the data?

I've attached a screen shot of the Chrome developer tools looking at a simple attempt to load and view csv data.

I'd really appreciate a hand here!
383912 (6) [Avatar] Offline
It looks to me as though you are not using a local server to provide the cities.csv file. As I understand it, modern browsers like Chrome prohibit a web page from reading local files in the user's file system.

You can either serve the data using a local server (like python's SimpleHTTPServer) which is the preferred way, I think. Or you can use a command line flag for Chrome which switches the protective mode off. Another way is to provide the data from cities.csv in your html file inside a <data> tag.

As I'm very new to web development I can't tell you see pros and cons of the various methods (other than that the command line flag method introduces a security hole to Chrome).
405748 (5) [Avatar] Offline
Hi - thanks for this!

Can you tell me where I'd get information on the command line flag for Chrome and/or the python server?
Much appreciated.

383912 (6) [Avatar] Offline
The python server comes with any standard installation of python.

Navigate to the folder containing your d3.js files and start the server via the command line: python -m SimpleHTTPServer
This is python 2.7, I think in python 3.x the name is not SimpleHTTPServer anymore.

The flag for allowing chrome to access the local filesystem is --allow-file-access-from-files
If you use the second option create a separate chrome launcher for learning d3, don't use this flag for general surfing on the internet, since it turns off a very basic safety feature.
405748 (5) [Avatar] Offline
Thank you very much for your help on this. John