title: flex_dashboard shiny_prerendered with eventReactive filtering
body: <p>I am trying to build a data heavy, calculation heavy shiny flex_dashboard with <code>runtime: shiny_prerendered</code>. 
  I would like all calculation and filtering be done on the server side and the rendering on the client side. 
  shiny_prerendered allows me to save on startup times for both the client and the server. In the below I have a simplified version of what I do. 
  I have a large dataset (<code>faithful</code> in the below). I am filtering that data according to the client's need. That filtered data should be used in all of the plots and results of the dashboard. 
  I put the libraries in <code>context="setup"</code>, the UI with <code>context="render"</code> (not needed as it is default).</p>
  
  <p>I also want to do the filtering and the plotting reactive to a button click. so I put in 
  <code>context="server"</code> two <code>eventReactive</code> functions. one for the filtering of data and one for the 
  selection of histogram bins.</p>
  
  <p>Finally for each result (plot or table), I put into the output variable the <code>renderPlot</code> and <code>renderTable</code> 
  in the <code>context="server"</code> and display them in the <code>context="render"</code>. In the 
  render functions (Plot or Table), I use the <code>eventReactive</code> functions that filter the data (and get the number of bins).</p>
  
  <p>The <code>faithful_filtered()</code> does the filtering and is called inside 2 <code>renderPlot</code> below. 
  1- Does that mean that the data is filtered twice? 
  2- Is the operation done two times? Since my data is very large I have many more 
  outputs in the real projects, that would be a very slow and inefficient.
  3- If the above 2 questions are affirmative, how do I get the button to filter the data first, then have that data be used in all the plots and tables to be rendered?</p>
  
  <p>here is the prototype code:</p>
  
  <pre><code>---
  title: "test shiny_prerendered with button"
  output: 
    flexdashboard::flex_dashboard:
      orientation: rows
  editor_options: 
    chunk_output_type: console
  runtime: shiny_prerendered 
  ---
  
  
  ```{r, include=FALSE, message=FALSE, context="setup"}
  library(tidyverse)
  library(flexdashboard)
  library(plotly)
  library(shiny)
  library(knitr)
  ```
  
  Input {.sidebar data-width=300}
  -------------------------------------
  
  ```{r, echo=FALSE, context="render"}
  sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)
  textInput("min_e", "min eruptions", min(faithful$eruptions))
  textInput("max_e", "max eruptions", max(faithful$eruptions))
  actionButton(inputId = "OK", label = "OK")
  ```
  
  ```{r, context="server"}
  nbins = eventReactive(input$OK, {input$bins})
  faithful_filtered = eventReactive(input$OK, {faithful %&gt;% filter(eruptions&gt;=input$min_e,
                                                                   eruptions&lt;=input$max_e)})
  
  ```
  
  Row
  -----------------------------------------------------------------------
  
  ### Plot 1 - filter reactive, bin reactive
  
  ```{r, context="server"}
  output$distPlot1 &lt;- renderPlot({
    x &lt;- faithful_filtered()[, 2]  # Old Faithful Geyser data
    bins &lt;- seq(min(x), max(x), length.out =  nbins() + 1)
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })
  ```
  
  ```{r, echo=FALSE}
  plotOutput("distPlot1")
  ```
  
  ### Plot 2 - twice the number of bins - filter reactive, bin is not
  
  ```{r, context="server"}
  output$distPlot2 &lt;- renderPlot({
    x &lt;- faithful_filtered()[, 2]  # Old Faithful Geyser data
    bins &lt;- seq(min(x), max(x), length.out = input$bins*2 + 1)
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })
  ```
  
  ```{r, echo=FALSE}
  plotOutput("distPlot2")
  ```
  
  ### Table - filter reactive
  
  ```{r, message=FALSE, context="server"}
  output$table = renderTable({
    head(faithful_filtered())
  })
  
  ```
  
  ```{r, echo=FALSE}
  tableOutput("table")
  ```
  </code></pre>