Can't use danfo-js library in my google script

1.1k views Asked by At

I wanted to find some library which is similar to pandas in Python and use it in my google script. I've found danfo-js https://github.com/opensource9ja/danfojs

And using this guide https://blog.gsmart.in/es6-and-npm-modules-in-google-apps-script/ did install it in google cloud shell so, actually here what I did:

  • opened my google cloud shell
  • installed clasp tools
  • clasp login
  • npm install danfojs-node
  • created new google script using: clasp create --type standalone --title "first GAS App"

So now, I have this empty script and just wanted to check does it see the danfo-js library.

To check this I have filled it out with the following code:

    function myFunction() {
      const dfd = require("danfojs-node")
      const tf = require("@tensorflow/tfjs-node")
      let data = tf.tensor2d([[20,30,40], [23,90, 28]])
      let df = new dfd.DataFrame(data)
      let tf_tensor = df.tensor
      console.log(tf_tensor);
      tf_tensor.print()
    }

After I run this script I am getting the following error message:

[20-10-18 06:17:53:783 PDT] ReferenceError: require is not defined at myFunction(Code:2:15)

It links on the following line:

    const dfd = require("danfojs-node")

Looks like the compiler doesn't know what is "danfojs-node" but I don't understand what steps did I miss.

I did install danfojs-node, using the following command in google cloud shell:

    npm install danfojs-node

and using the same terminal window I created this script.. maybe I should set some link inside the script to connect to this library, but I don't know where should I do it.

1

There are 1 answers

0
ale13 On

Apps Script is not Node.js.

You cannot install external modules and libraries the same way you would when creating a node.js application. The supported way of using external libraries in Apps Script is by installing them through the project's resources.

So essentially, this can be done by going to the project's Resources > Libraries....

You have to check if the library you plan on using is supported by Apps Script and if so, include it using the step above.

Reference