How do I format my output to be on top of each other instead of side to side?

Viewed 41

I am using Googles NLP in Apps Scripts and the data is pulling through. However my output is displaying horizontally instead of on-top of each other. Probably a simple change but I'm not able to figure it out. In the screenshot I shared I would like the number 0.3 to be under the metric 2.10 (in yellow). Any advice would be helpful.

enter image description here

function SentimentAnalysis(text)
{
  if (text == undefined || text == null || text == "")
  {
    throw "No text was specified for performing sentiment analysis."
  }
  
  var URL_PREFIX = "https://language.googleapis.com/v1/documents:analyzeSentiment?fields=documentSentiment&key=";
  
  // retrieve api key;
  var apiKey = PropertiesService.getScriptProperties().getProperty("GOOGLE_CLOUD_API_KEY");
  if (apiKey == null || apiKey == "REPLACEME" || apiKey == "") {
    PropertiesService.getScriptProperties().setProperty("GOOGLE_CLOUD_API_KEY", "REPLACEME");
    throw "Specify your GOOGLE_CLOUD_API_KEY via User Properties (File->Project Properties, Script Properties)";
  }
  
  var url = URL_PREFIX + apiKey;
  
  // define the request
  var data = {
    "document": {
      "content": text,
      "type": "PLAIN_TEXT"
    },
    "encodingType": "UTF8"
  };
  
  var options = {
    "method" : "POST",
    "contentType" : "application/json",
    "payload" : JSON.stringify(data)
  };

  // make the request
  var response = UrlFetchApp.fetch(url, options);
  
  // get the response
  if (response.getResponseCode() != 200) {
    throw "Unexpected response code from Google.";
  }
  
  var responseText = response.getContentText();

  if (responseText == null || responseText == "") {
    throw "Empty response from Facebook.";
  }

  // parse the response
  var magnitude = 0, score = 0;
  try
  {
    var sentimentResponse = JSON.parse(responseText, false);
    magnitude   = parseFloat(sentimentResponse.documentSentiment.magnitude);
    score    = parseFloat(sentimentResponse.documentSentiment.score);
  }
  catch (e)
  {
    throw "Unreadable response from Google: " + e;
  }
  
  return [[magnitude, score]];
}

1 Answers

I believe your goal as follows.

  • You want to put the values of magnitude and score to the vertical direction.
  • You are using the function of SentimentAnalysis as the custom function.
  • magnitude and score are the correct values you expect.

In this case, how about the following modification?

From:

return [[magnitude, score]];

To:

return [magnitude, score];

or

return [[magnitude], [score]];
Related