Search code examples
javascripthtmld3.jsvisualization

Access a txt local file with d3


I am new with D3, Javacript, and HTML.

The repository of my project is as follows: Project:

  • facebook_combined.txt
  • index.html
  • network.js

I am trying to access facebook_combined.txt from index.html to try to do a first visualization of it. Here is the console when I execute the index.html

This is index.html This is network.js

I have tried to reproduce other project online but I always get this error. My guess is that I am trying to access a local file from the server which doesn't have access to it. I didn't find a way to run the html locally or to put the txt file online in a way that the server can reach it.


Solution

  • You cannot fetch local files because this would raise dramatic security concerns. (Imagine a script could just retrieve a file "C:\mypasswords.txt" ...)

    If you want this to run locally, include the contents of "facebook_combined.txt" directly into your script or html.

    Otherwise your html and script file as well as the txt need to be accessible online.