0

Can you download the entire module of plotly using node js. Right now, I am streaming data with plotly using node js by using my API keys. If there is a way, can yo give step by step instructions? I tried https://www.npmjs.com/package/plotly.js, but it does not work.

var plotly = require('plotly.js');
  var initdata = [{x:[], y:[], stream:{token:'t2166m92ft', maxpoints:50}}];
    var initlayout = {fileopt : 'overwrite', filename : 'nodenodenode5'};

    plotly.plot(initdata, initlayout, function (err, msg) {
      if (err) return console.log(err);
      console.log(msg);

      var stream1 = plotly.stream('t2166m92ft', function (err, res) {
        if (err) return console.log(err);
        console.log(res);
        clearInterval(loop); // once stream is closed, stop writing
      });

          var i = 0;
          var loop = setInterval(function () {
            client.once('message', function (message) {
            var data = { x : i , y :  message.toString()};
            var streamObject = JSON.stringify(data);
            stream1.write(streamObject+'\n');
            i++;
            });
          }, 5000);
    });
  }

when i tried install using npm install plotly.js, and ran my program I got :

\Users\intern\Documents\universal-ground-system\Node js\node_modules\plotly.js
rc\lib\index.js:397
      var style = document.createElement('style');
              ^

ReferenceError: document is not defined
  at Object.lib.addStyleRule (C:\Users\intern\Documents\universal-ground-syste
Node js\node_modules\plotly.js\src\lib\index.js:397:21)
  at Object.<anonymous> (C:\Users\intern\Documents\universal-ground-system\Nod
js\node_modules\plotly.js\build\plotcss.js:61:16)
  at Module._compile (module.js:409:26)
  at Object.Module._extensions..js (module.js:416:10)
  at Module.load (module.js:343:32)
  at Function.Module._load (module.js:300:12)
  at Module.require (module.js:353:17)
  at require (internal/module.js:12:17)
  at Object.<anonymous> (C:\Users\intern\Documents\universal-ground-system\Nod
js\node_modules\plotly.js\src\plotly.js:30:1)
  at Module._compile (module.js:409:26)

2 Answers 2

1

Plotly open source library can not be used in node js. But can be used on client side javascript.

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

Comments

0

I got past this to some degree, but ran into another error, so close now it seems.

When I make a dom with jsdom it doesn't like to see window for some sort of async issue probably. If you go into REPL load the file or otherwise get to make the new jsdom object, then you can do this sort of thing in REPL that references window and the needed document.

let jsdom = lib.require('jsdom');

//let window = (new jsdom.JSDOM('<p>Hello</p>')).window;

let dom = new jsdom.JSDOM('<p>Hello</p>');

/* While just testing I do this in REPL after .load index.js
let window = dom.window;
let document = window.document;
*/

So then I get a new error after npm install canvas that needs

apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++

first to properly build it on Ubuntu 16

so the new error is...

> let window = dom.window;
undefined
> let document = window.document;
undefined
>
>
> let plt = lib.require('plotly.js');
ReferenceError: self is not defined
at Object.254 (./node_modules/mapbox-gl/dist/mapbox-gl.js:509:29)
at s (./node_modules/mapbox-gl/dist/mapbox-gl.js:1:684)
at ./node_modules/mapbox-gl/dist/mapbox-gl.js:1:735
at Object.252../window (./node_modules/mapbox-gl/dist/mapbox-gl.js:505:25)
at s (./node_modules/mapbox-gl/dist/mapbox-gl.js:1:684)
at ./node_modules/mapbox-gl/dist/mapbox-gl.js:1:735
at Object.73.../package.json (./node_modules/mapbox-gl/dist/mapbox-gl.js:146:75)
at s (./node_modules/mapbox-gl/dist/mapbox-gl.js:1:684)
at e (./node_modules/mapbox-gl/dist/mapbox-gl.js:1:855)

>

I tried setting 'self' to 'document' and 'this' and get another error.

> self = document;
Document { location: [Getter/Setter] }
> plt = lib.plt = lib.require('plotly.js');
TypeError: Cannot read property 'hardwareConcurrency' of undefined
at Object.252../window (./node_modules/mapbox-gl/dist/mapbox-gl.js:505:834)
at s (./node_modules/mapbox-gl/dist/mapbox-gl.js:1:684)
at ./node_modules/mapbox-gl/dist/mapbox-gl.js:1:735
at Object.73.../package.json (./node_modules/mapbox-gl/dist/mapbox-gl.js:146:75)
at s (./node_modules/mapbox-gl/dist/mapbox-gl.js:1:684)
at e (./node_modules/mapbox-gl/dist/mapbox-gl.js:1:855)
at ./node_modules/mapbox-gl/dist/mapbox-gl.js:1:873
at ./node_modules/mapbox-gl/dist/mapbox-gl.js:1:150

Next I attempted to get window.navigator into self but that's apparently got nothing to do with the error. Somewhere else in mapbox-gl.js is glitching out.

I've only found a reference to harwareConcurrency in mapboxgl.js here https://github.com/mapbox/mapbox-gl-js/issues/899

Seems misleading to say it's a nodejs library when it only works in the browser? https://plot.ly/nodejs/

Just now I'm seeing something about an API Key? I guess I'm barking down the wrong tree sideways. Big mistake here.

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.