Streaming custom function in Google Sheets?

94 views
Skip to first unread message

Tuan Do

unread,
Jan 3, 2022, 7:56:44 AM1/3/22
to Google Apps Script Community
Just wondering whether there is a way to build a custom function in Google Sheets that can stream real-time data? I am trying to build a custom function which can receive data from my website every second and display it in the cell. Basically I need a function that reruns every second (or every few seconds is also fine).

I have tried to search for something like this but could not find the answer. I have also though about using time trigger to rerun the functions every second but add-on's custom functions can only rerun every hour if we use time trigger.

Appreciate any help.

Bennett, Scott

unread,
Jan 3, 2022, 8:09:04 AM1/3/22
to google-apps-sc...@googlegroups.com
You can use an installable trigger on App Script.  They can run every minute. 

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a2145f7b-d9b4-46b4-9e09-f47906baa9afn%40googlegroups.com.


--
Scott Bennett


Tuan Do

unread,
Jan 3, 2022, 8:33:37 AM1/3/22
to Google Apps Script Community
Thanks for your answer. Every minute unfortunately does not work for me. I am looking for something more frequent than that (at least every 5 seconds)

Jonathan Butler

unread,
Jan 3, 2022, 9:59:35 AM1/3/22
to google-apps-sc...@googlegroups.com
I don't see why that couldn't work, besides the UrlFetchApp quota. As long as the data is under a certain amount, you can do it pretty easily with one custom function. You have set the custom function reference to be the start and end area of the data you want to view. Upon a change, all data gets sent to that function automatically, then just UrlFetchApp to your api endpoint.

Tuan Do

unread,
Jan 3, 2022, 10:02:40 AM1/3/22
to Google Apps Script Community
How do I make that function automatically rerun every 5 seconds? time trigger can only run every minute.

Jonathan Butler

unread,
Jan 3, 2022, 10:06:25 AM1/3/22
to google-apps-sc...@googlegroups.com
It runs every time there is an edit. To my knowledge, there would be no need to run when there is no edit. If you can give me more details on the environment I can be of better help.

Do Quoc Tuan

unread,
Jan 3, 2022, 10:16:55 AM1/3/22
to google-apps-sc...@googlegroups.com
Oh I need it to rerun automatically every 5 seconds without any editing required. Essentially I am trying to build a streaming function.

You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/V6lCBqAaZO4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAE9k5yC6jO%2BGYS_bMmDegiuavHre9Xdpr5jq-WPYUdh06u_1oA%40mail.gmail.com.

Jonathan Butler

unread,
Jan 3, 2022, 10:24:29 AM1/3/22
to google-apps-sc...@googlegroups.com
This should help you out.

- Create a trigger that calls a function every 5 minutes.
- The function is a while loop that sends the data, then sleeps for 3 seconds.
- Then the program terminates itself after 5 minutes by checking the time difference from the start time every run.

Tuan Do

unread,
Jan 3, 2022, 12:20:48 PM1/3/22
to Google Apps Script Community
Thanks for your answer. That idea may work. Just wondering whether there is an easier way than that? In Excel there is something called streaming function: https://docs.microsoft.com/en-us/office/dev/add-ins/excel/custom-functions-web-reqs#make-a-streaming-function. We can even use websocket in Excel custom function. I am hoping Google App Script has something similar
Reply all
Reply to author
Forward
0 new messages