Jon
Jon

Reputation: 39

Google App Scripts: When running script, chart output isn't being generated

I am trying to concatenate my html files and output them using one doGet() as so:

function doGet() {
  return HtmlService.createTemplateFromFile('Index').evaluate()
}

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename).getContent()
}

However, the charts don't generate. If i pass in one file via Index.html I get this output. It's literally the code I wrote in the editor.

<html> <head> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Tangerine"> <style> body { font-family: 'Tangerine', serif; font-size: 35px; } </style> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> // Load Charts and the corechart package. google.charts.load('current', {'packages': ['table']}); google.charts.load('current', {'packages':['corechart']}); google.charts.load('current', {'packages':['bar']}); google.charts.load('current', {'packages':['line']}); //Draw table for data google.charts.setOnLoadCallback(drawTable); //draw Line Chart for data google.charts.setOnLoadCallback(drawLineChart); //draw bar chart for data google.charts.setOnLoadCallback(drawBarChart); // Draw the pie chart for Date1 google.charts.setOnLoadCallback(drawApr1Chart); // Draw the pie chart for Date2 google.charts.setOnLoadCallback(drawApr3Chart); //Draw the pie chart for Date3 google.charts.setOnLoadCallback(drawApr10Chart); //Draw the pie chart for Date4 google.charts.setOnLoadCallback(drawApr24Chart); //draw the material line chart for all issues vs date when Charts is loaded google.charts.setOnLoadCallback(drawIssuesvsDate); function drawTable() 

Not sure why that's the case. I have managed to successfully concatenate html outputs before so I am not sure what the problem is.

Upvotes: 0

Views: 49

Answers (1)

Karl_S
Karl_S

Reputation: 3554

In your HTML file, prior to teh tag, place the following:

<?!= HtmlService.createHtmlOutputFromFile('myFileName').getContent(); ?>

or

<?!= include('myFileName'); ?>

where myFileName is the name of the other html file you wish to include from your project.

Note that the first option removes the need for the include() function in your .gs file while the second option allows for an easy edit if the HTMLservice calls change or are deprecated.

Edit from the comment: I did not check your include() function with the one I have been using. This is how mine reads:

function include(filename) {
//  return HtmlService.createHtmlOutputFromFile(filename)
  return HtmlService.createTemplateFromFile(filename).evaluate()
      .getContent();
}

Note the addition of the .evaluate()

Upvotes: 1

Related Questions