How can I show the sidebar for anonymous viewers (or editors)? I tried using normal and installable triggers:
Normal Triggers:
function onOpen(){
var html = HtmlService.createHtmlOutputFromFile('Page')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('My custom sidebar')
.setWidth(300);
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showSidebar(html);
}
This worked with the owner of the spreadsheet but didn't work with anonymous users although anyone with the link has editing permission.
Installable Triggers:
function showSidebar(){
... the same body of the previous 'onOpen' function
}
Then, I bound the function showSidebar to an installable trigger that is called when the spreadsheet is opened.
This didn't work with either the owner or an anonymous user!
Finally, I tried binding the function showSidebar to an image inserted into the spreadsheet but didn't work with an anonymous user. It displays a message saying
Script showSidebar experienced an error
and even if the final method worked well, it will not show the sidebar automatically.
It looks to me that the code is almost the same of https://developers.google.com/apps-script/guides/dialogs#custom_sidebars. That has two files, Code.gs and Page.html. As the OP didn't mentioned the code of Page.html it's very likely that it was missing on his attempt as using the same code as the OP worked just fine if the code of the Page.html file is include and the file is opened by the owner of by an editor.
Regarding running as anonymous user, the onOpen doesn't run when the spreadsheet is opened by an anonymous with view or edit access. There is a report related to this in the Google Apps Issue Tracker
Issue: 5747 Trigger for anonymous user / script for anonymous user
UPDATE:
From an answer by +Samantha to a similar thread in the Google Docs Help Forum
Code from the first link
Code.gs
Page.html