Thursday, November 29, 2012

Creating a GUI Application (Part 2)

Note Added 2013-06-02: The GUI Builder is being phased out, Html Service is now the preferred GUI tool, see blog entry on this.
Creating A web Service
  • The mortgage app from part 1 can also be run as a web service and to do so requires only a few more steps but no changes to the GUI itself.
  • The important point here is that the web service, although it was created in a Google Spreadsheet, runs completely independently of the spreadsheet and could just as easily and effectively been created from a Google Site.
The code in “calculate()” remains the same but the following code replaces “onOpen()” and “showGui()” in the spreadsheet version:

 "use strict;"
function doGet() {
  var app = UiApp.createApplication();
  var guiName = 'MortgageGui';
  return app;

To deploy as a web service:
  • There needs to be a function named “doGet()” as above that returns the app.
  • In the script editor, you need to select File->Manage Versions....  Enter some something and save the version.
  • Then, once again in the script editor, select Publish->Deploy as web app...
  • Copy the URL that is generated and paste it into the browser to view the web page where an ugly but functional form will appear.
  • The URL I created is here:
You will need to authorize it.
The previous blog entry showed a screen shot that displayed the web application so it has not been re-shown here.

The example given here, though very simple and not visually pleasing, does hint at the power of this approach to deliver sophisticated applications over the web.  Here the form just takes some input, does some calculations on it, and then displays the results on the form.  But these types of applications could be hooked up to back-end persistent data repositories such spreadsheets or cloud MySQL databases to enter, retrieve, or analyze data.
This examples requires code version management before the app can be published.  Code versioning is a very good thing and is often neglected by Excel VBA developers.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.