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

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.

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
Apps Script Libraries.

Related

Error working with google apps script locally in VSCode using CLASP and push command

I have cloned a google apps script project but when trying to deploy the changes with the push command I get the following error:
PS D:\evcPRD> clasp push
No valid D:\evcPRD.clasp.json project file. You may need to create or clone a project first.
Any idea how to solve this?
Thank you

google cloud functions: downloading a file to the root directory python 3.9

I have a file I need to get into the Google Cloud Function's directory for a multi-step problem. Matplotlib: Custom fonts in cloud functions using Python 3.9
I'm not sure how to do it. Do I do it as a function in cloud functions? or use the console terminal for the project? I tried that and looked in the root directory and there was nothing there. I can only change projects and not change to a specific function directory.
Can someone please show me how to put this file https://www.1001freefonts.com/balthazar.font into the function's file system so it can be called during execution?
When you deploy a Cloud Function to GCP, you can supply a ZIP file or a directory that contains your source code and additional artifacts/files that you may need.
To perform the deployment of the ZIP or directory, you will want to use the gcloud command. A good article on this is Deploying from Your Local Machine.
The detailed documentation on the CLI can be found at gcloud functions deploy.
In your example, you could create a directory that contains your source and your font file and both will be present in the context of the Cloud Function. I believe that if you want to reference the files, you will want to use the local current directory in your code. For example, instead of coding /myfontfile.font you might code ./myfontfile.font.
Here are some references to this technique:
Cloud Functions: how to upload additional file for use in code?

Google assistant action, no function URL

i would like to create an action project. I have an issue when i run firebase deploy --only functions.
Before i run: npm install -g firebase-tools, firebase login, firebase init, npm install actions-on-google, npm install
Everything is working and it says: Deploy complete. But it doesnt deliver me the function URL in the CMD. Also when i look it up over here : https://console.firebase.google.com/.../functions/list it doesnt show me the URL.
Do you have any idea what i am doing wrong?
That is the Tutorial i am doing:
https://developers.google.com/actions/tools/fulfillment-hosting
Best regards
Luca
You need to export a function otherwise Firebase cannot run/deploy it. You can view some great code examples on how to make Actions on the Google Assistant with Firebase here.
The following code should help you get started.
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const app = dialogflow({debug: true});
exports.myFunction = functions.https.onRequest(app);

Clasp fail while running

I am using the clasp to run AppScript
Example:
clasp run myFunction dev
but its showing error here like
Requested entity was not found
please let me know why it's happening?
You need to deploy the script as "API Executable". Then add sufficient authorization scopes to call the function.

Update Google Apps Scripts Library Version on Client Side?

I have several dozen Google Sheets that I manage for my company that all use the same Apps Scripts library and I am trying to find the easiest way to be able to update the library and have the changes propagated to the Google Sheets. I understand the use Development mode so that the Google Sheets using the library have the most up-to-date code however that requires giving edit privileges of the Apps Scripts project to the Google Sheets users.
The alternative is to turn Development Mode off so that users would only require read privileges however, to then update the code used by the Google Sheets, I would need to save a new version of the Apps Scripts library and then manually update every Google Sheet with the new library version.
Is there anyway to update the library version used by a Google Sheet using one of the Google APIs or some other way that could be done programmatically?
Sorry for answering after 1 year,
If i understand, you have a Script Project which is a library for several users project and your problem is to deploy a livrary version in every client project.
As Alan Wells says, you just have to replace the manifest of each client project.
Your manifest is a appsscript.json file. (you could show/hide the manifest file in a project)
Manifest file syntax :
{
"timeZone": "XXX",
"dependencies": {
**** SOME dependencies you need for the client****
,
"libraries": [{
"userSymbol": "MAIN_SCRIPT_NAME",
"libraryId": "MAIN_SCRIPT_ID",
"version": "MAIN_SCRIPT_VERSION"
}]
},
"exceptionLogging": "STACKDRIVER"
}
You could use CLASP to manage your script easily.
In your example, in clasp, you create a master folder for your project and a subfolder for every Clients Script. You need to sync every subfolder to his GoogleAppsScript.
The initialisation could be long and boring, but with a little shell you be able to push the manifest to every client script with on click/script..
You just have to modify the manifest into your Master Folder and run a script like :
for x in `ls -d SubFolder*`; do (cp appsscript.json $x ; cd $x; clasp push -f >/dev/null ; cd ..; echo "Update done on "$x) ; done
Now you can update the manifest for every client, Library version is available, but the dependencies too... (if you need start some new, or end others)