Standalone web apps are one of the most powerful ways to leverage Google Apps Script. Unlike bound scripts that operate within a specific Google Workspace application (like Sheets or Docs), standalone web apps can be accessed via a unique URL, making them accessible to anyone with the link, or even integrated into external websites. This opens up a world of possibilities for creating custom dashboards, interactive forms, data visualization tools, and much more, all without needing to share your underlying Google Sheet or Doc.
To create a standalone web app, you'll start by creating a new Apps Script project. Navigate to script.google.com and click 'New project'. You'll then write your script, which typically includes a function to handle requests and return content. The doGet() function is specifically designed for this purpose. When your web app is deployed, Apps Script automatically calls this function when a user accesses the app's URL.
function doGet(e) {
return HtmlService.createHtmlOutput('<h1>Welcome to my Standalone Web App!</h1>');
}The doGet(e) function receives an event object e which contains information about the incoming request, such as query parameters. In its simplest form, as shown above, it returns an HtmlOutput object. This output can be plain HTML, or you can use HtmlService to serve more complex HTML files from your script's project (Files > New > HTML file). This allows for dynamic content generation and user interfaces.
Once your script is ready, you need to deploy it as a web app. Go to 'Deploy' > 'New deployment'. In the 'Select type' dropdown, choose 'Web app'. Configure the 'Execute as' and 'Who has access' settings according to your needs. For public access, select 'Anyone'. For internal use, you might choose 'Only myself' or 'Anyone within your domain'. After saving, you'll receive a unique URL for your web app. Remember that changes to your script require a new deployment to be reflected in the live web app.
graph TD
A[User Accesses URL] --> B{Apps Script Server};
B --> C{doGet(e) function called};
C --> D[Generates HtmlOutput];
D --> E[Returns HTML to User Browser];
It's important to understand the 'Execute as' setting. 'Me' means the script runs with your Google account's permissions, allowing it to access your Google Drive, Calendar, etc. 'User accessing the web app' means the script runs with the permissions of the person who clicks the URL. This is crucial for security and data privacy when sharing your web app.