general way of moving data in-line?

19 views
Skip to first unread message

Ruud Steltenpool

unread,
Dec 8, 2016, 2:21:15 AM12/8/16
to d3-js
When you find an example that loads in data from a URL (proper way), but want to show it somewhere where you can't reach any server (not even in the machine itself, not having the credentials to install anything either).
What then?
And how could D3 API/docs be improved to cater for this situation?

Vlado Z

unread,
Dec 8, 2016, 3:16:02 AM12/8/16
to d3-js
Make a local copy of the data in a file and use local http server to read it and display it in a browser?

Vlado Z

unread,
Dec 8, 2016, 3:19:39 AM12/8/16
to d3-js
Install either Node JS  with http-server or Apache httpd server with PHP 5 and run some simple script along with JQuery AJAX(D3 has also its own AJAX support) script and load the data file which is locally on your http server inside the upload folder.

Hope this clarifies a bit.

Ruud Steltenpool

unread,
Dec 8, 2016, 3:49:32 AM12/8/16
to d3-js
The data needs to go in-line of the HTML because:
- The end user has NO company http-server credentials or credentials to intall it locally, so no AJAX available
- As the data might be sensitive, a http-server outside of the company is also not allowed

So,
what is the general way of turning a typical AJAX based data-loading into in-line data-loading?
I'd love to even automate it, so I can bake the dataIncluded.html and mail it of

Vlado Z

unread,
Dec 8, 2016, 4:13:22 AM12/8/16
to d3-js
You don't need credentials username and password to install http server, you just need a computer that can run it. You can also enable HTTPS which stands for secure HTTP and you can send sensitive data over web, encrypted. AJAX is JavaScript and can go inside a browser on the same computer.

If pulling some documents from the company outside is not allowed, you should ask them for permission and whether they can give you remote access.

Ruud Steltenpool

unread,
Dec 8, 2016, 4:37:43 AM12/8/16
to d3-js
There are corporate locked-down machines you can't install anything on, unless you have credentials, which no one gets.
Asking for permission takes a long long time, plus not needed if my primary question is answered.
I've used ajax many times, that is not the problem. The problem is that ajax doesn't work over file:// protocol
You know those annoying places where you have no coverage whatsoever? There it should still work, from the machine itself.

Vlado Z

unread,
Dec 8, 2016, 5:50:52 AM12/8/16
to d3-js
Yes you need http server to use AJAX. My idea was to tell you that you can use home computer or laptop where you can install locally http server and load data with AJAX and show it with D3. But again I don't know your company rules.

You might wanna try Openshift. It is a platform for creating web applications. You just tell it which gears to install, for example PHP 5. This will install Apache httpd server and you can upload your own code which can then be run and accessed for free over web.
Plus for a fee you can make your application 24/7 available on the web.
But its kind of tricky to set up. You will need to install some tools to get you started.

Curran

unread,
Dec 8, 2016, 8:19:42 AM12/8/16
to d3-js
Hi Ruud,

One thing that has worked for me in the past for this is to have a tag that contains CSV text, then parse the data from that DOM element. You can use a <script> tag so the browser doesn't try to render the content, and set type="text/csv" so the browser doesn't try to parse it as JS.

Here's an example:

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>

    <!-- Paste the CSV data into this tag (careful about white space). -->
    <script type="text/csv" id="inline-data">A,B
1,3
4,5</script>

    <script>

      var csvStr = d3.select("#inline-data").text();

      var data = d3.csvParse(csvStr);

      console.log(JSON.stringify(data, null, 2));

      // Prints:
      //
      //[
      //  {
      //    "A": "1",
      //    "B": "3"
      //  },
      //  {
      //    "A": "4",
      //    "B": "5"
      //  }
      //]
      
    </script>
  </body>
</html>

Best regards,
Curran

Peter Cook

unread,
Dec 8, 2016, 10:08:08 AM12/8/16
to d3-js
Is it CSV (in which case Curran's solution has worked for me too) or JSON (in which case you can assign it to a variable)?
Reply all
Reply to author
Forward
0 new messages