Passing output of reactive function to another reactive function (Shiny)
<p>I have a dataset that looks as the following one (but the actual dataset is much larger and contains some additional columns):</p>

<pre><code>"month","year","id","hour","count"
1,2015,"place001",13,10.2319100637371
6,2015,"place001",14,42.2066290129154
10,2015,"place002",18,34.5326964651126
3,2015,"place002",8,23.0217976434084
3,2014,"place002",1,19.184831369507
3,2014,"place003",15,47.322584044784
</code></pre>

<p>I'm trying to build a Shiny app to explore this data. This is what I got so far, but it breaks when it tries to process the <code>quarterly</code> reactive function. If I use the "redundant" approach that is commented out, the app renders correctly, however I want to avoid it.</p>

<p>Later I will also need to use the output of <code>totals</code> and reshape it with the <code>melt</code> function, so I want to understand how I can use this reactive function as input for another reactive function.</p>

<p>Any help is greatly appreciated.</p>

<h3>ui.R</h3>

<pre><code>library(shiny)
library(ggvis)

renderInputs &lt;- function() {
  wellPanel(
    ## Take hour information from user for filtering.
    checkboxGroupInput("hour", "Hours",
                       c("1" = 1,
                         "8" = 8,
                         "13" = 13,
                         "14" = 14,
                         "15" = 15,
                         "18" = 18),
                       selected  = c(1, 8, 13, 15),
                       inline = T)
  )
}

shinyUI(fluidPage(
  titlePanel("Analysis"),

  fluidRow(
    ## Inputs
    column(4, renderInputs()),
    ## Plot data.
    column(8,h2("Monthly Visitors"),
           ggvisOutput("plotM")
    )),
    ## Plot quarterly data.
  fluidRow(
    column(7, h2('Quarterly Summary'),
    ggvisOutput("plotQ"))
    )
))
</code></pre>

<h3>server.R</h3>

<pre><code>library(shiny)
library(dplyr)
library(zoo)

data &lt;- read.csv("file.csv")
data$date &lt;- as.yearmon(paste0(data$year, "-", data$month))

shinyServer(function(input, output) {

    totals &lt;- reactive({
      data %&gt;%
        filter(hour %in% input$hour) %&gt;%
        group_by(date) %&gt;%
        summarize(visitors = sum(count))
    })

    ## Quarterly, with "reactive" approach.
    quarterly &lt;- reactive({
      totals() %&gt;%
        mutate(quarter = as.yearqtr(date)) %&gt;%
        group_by(quarter) %&gt;%
        summarize(visitors = sum(count))
    })


    ## Quarterly data and percentage changes (redudant approach).
#    quarterly &lt;- reactive({
#    data %&gt;%
#      filter(hour %in% input$hour) %&gt;%
#      mutate(quarter = as.yearqtr(date)) %&gt;%
#      group_by(quarter) %&gt;%
#      summarize(visitors = sum(count))
#    })

    ## Create estimated quarterly chart.
    visM &lt;- reactive({
      totals() %&gt;%
        ggvis(~as.factor(date), ~visitors) %&gt;%
        layer_points()
    })  

    ## Create estimated quarterly chart.
    visQ &lt;- reactive({
      quarterly() %&gt;%
        ggvis(~as.factor(quarter), ~visitors) %&gt;%
        layer_bars(fill := "green")
    })


    ## Send plots to UI.
    visM %&gt;% bind_shiny("plotM")

    visQ %&gt;% bind_shiny("plotQ")
})
</code></pre>

<p>Thanks.</p>