Mapply over multiple Google Analytics API queries in Shiny app
<p>I'm looking to <code>mapply</code> over multiple <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/" rel="nofollow">Google Analytics Core Reporting API</a> queries in a <a href="http://www.shinyapps.io/" rel="nofollow">Shiny</a> app, using 3 input variables dictated by each row of a data frame. To access the Google Analytics API through R, am using the CRAN <a href="https://cran.r-project.org/web/packages/RGA/RGA.pdf" rel="nofollow">RGA</a> library.</p>

<p>In my <code>ui.R</code>, I have <code>textOutput</code> mapped to each <code>i</code> in <code>df$name</code>. This way, <code>output$name</code> should render the results of both queries for each <code>i</code> in <code>df$name</code>.</p>

<p>Currently, my console prints:</p>

<blockquote>
  <p>"No results were obtained."</p>
</blockquote>

<p>I have tested the queries individually, and they both should pull results.</p>

<p>This is a reduced version of my server.R:</p>

<pre><code>shinyServer(function(input, output) {
  library(RGA)
  thisWeekEnd&lt;-"2016-01-17"
  thisWeekStart&lt;-as.character(as.Date(thisWeekEnd)-7)
  lastWeekEnd&lt;-as.character(as.Date(thisWeekEnd)-8)
  lastWeekStart&lt;-as.character(as.Date(thisWeekEnd)-13)
  startOfCampaign&lt;-"2015-12-23"

  df &lt;- data.frame(
    start= c(thisWeekStart,lastWeekStart,startOfCampaign),
    end =c(thisWeekEnd,lastWeekEnd,thisWeekEnd),
    name=c("thisWeek","lastWeek","total"), stringsAsFactors=FALSE)

  gaData&lt;-function(start,end,name){

    query1 &lt;- get_ga(
      id,
      start.date = start, 
      end.date = end,
      metrics = "ga:sessions",
      )

    query2 &lt;- get_ga(
      id,
      start.date = start, 
      end.date = end,
      metrics = "ga:uniqueEvents",
      )

   output$name&lt;-renderText({
        paste(as.character(query1$sessions)," sessions",
        as.character(query2$unique.events)," unique events"
        )})
  }

  mapply(gaData, df$start,df$end,df$name)
}
</code></pre>