title: R Shiny Reactive dplyr filters to form new dataframe to plot from
body: <p>I am trying to build a reactive plot that uses dplyr filter functions reactive to user inputs to pull the correct x,y coordinates to plot. </p>
  
  <p>My UI: </p>
  
  <pre><code>choices &lt;- c("Web" = 1,"Huddle" = 3, "Other" = 5, "Test" = 7)
  role &lt;- c("Student" = 1, "Not" = 2)
  range &lt;- c("2016"=2,"July 2017"=1)
  
  ui &lt;- dashboardPage(
    dashboardHeader(title="Membership Satisfaction"),
    dashboardSidebar(
      sidebarMenu(
        menuItem("Value Dashboard", tabName = "dashboard", icon = 
  icon("dashboard")),
    menuItem("Services Dashboard", tabName = "service", icon = 
  icon("dashboard")),
    menuItem("Demographics Dashboard", tabName = "demos", icon = 
  icon("dashboard"))
      )
    ),
    dashboardBody(
      tabItems(
  
        tabItem(tabName = "demos",
            sidebarPanel(
              checkboxGroupInput("inpt","Select variables to plot", choices = 
              choices),
              checkboxGroupInput("role", 
                                 "Select Primary Role of Interest", 
                                 choices = role),
              checkboxGroupInput("yrs", 
                                 "Select year(S) of Interest", 
                                 choices = range)),
            fluidPage(
  
              plotOutput("test")  
  
            )))))
  </code></pre>
  
  <p>and my server:</p>
  
  <pre><code>server &lt;- function(input,output){
  
  
    x &lt;- reactive({
      example1 %&gt;%
      dplyr::filter(Product == as.integer(input$inpt))%&gt;%
      dplyr::filter(year == as.integer(input$range)) %&gt;%
      dplyr::filter(status == as.integer(input$role)) %&gt;%
      pull(-2)
     })
  
  
    y &lt;- reactive({
      example1 %&gt;%
        dplyr::filter(Product == as.integer(input$inpt+1))%&gt;%
        dplyr::filter(year == as.integer(input$range)) %&gt;%
        dplyr::filter(status == as.integer(input$role)) %&gt;%
        pull(-1)
    })
  
    z &lt;- reactive({data.frame(x= x(), y = y())})
  
  
    output$test &lt;- renderPlot({
  
      ggplot(z(), aes(x,y))+ 
      geom_point(colour ="green", shape = 17, size=5 )+ 
      labs(x = "Mean Satisfaction", y = "Mean Importance") + 
      xlim(0,5) + ylim(0,5)+
      geom_vline(xintercept=2.5) + geom_hline(yintercept =  2.5)})
  
  
         }
  
  
  
     shinyApp (ui = ui, server = server)
  </code></pre>
  
  <p>Notes: </p>
  
  <p>Example1 is a dataframe with summarized averages by group, year, and product. </p>
  
  <p>X and Y variables filter to get a particular product code and stores just the mean values. Y is a corresponding and always product(x+1). It gets the average for y and stores those vales. Variable Z then creates a dataframe of x,y coordinate points to plot. </p>
  
  <p>Example1 data head:</p>
  
  <pre><code>&gt; example1
  # A tibble: 24 x 5
  # Groups:   year, status [12]
      year status Product AvgComImpt AvgComSat
      &lt;dbl&gt;  &lt;dbl&gt; &lt;fct&gt;        &lt;dbl&gt;     &lt;dbl&gt;
   1    1.     1. 1           NaN         2.70
   2    1.     1. 2             3.13    NaN   
   3    1.     2. 1           NaN         2.43
   4    1.     2. 2             3.33    NaN   
   5    1.     3. 1           NaN         2.40
   6    1.     3. 2             3.60    NaN   
   7    1.     5. 1           NaN         3.03
   8    1.     5. 2             3.30    NaN   
   9    1.     7. 1           NaN         3.50
  10    1.     7. 2             4.00    NaN   
  
  
  &gt; dput(head(example1))
  structure(list(year = c(1, 1, 1, 1, 1, 1), status = c(1, 1, 2, 
  2, 3, 3), Product = structure(c(1L, 2L, 1L, 2L, 1L, 2L), .Label = c("1", 
  "2"), class = "factor"), AvgComImpt = c(NaN, 3.12844036697248, 
  NaN, 3.33333333333333, NaN, 3.6), AvgComSat = c(2.7037037037037, 
  NaN, 2.42857142857143, NaN, 2.4, NaN)), .Names = c("year", "status", 
  "Product", "AvgComImpt", "AvgComSat"), row.names = c(NA, -6L), class = 
  c("grouped_df", 
  "tbl_df", "tbl", "data.frame"), vars = c("year", "status"), drop = TRUE, 
  indices = list(
  0:1, 2:3, 4:5), group_sizes = c(2L, 2L, 2L), biggest_group_size = 2L, labels 
  = structure(list(
  year = c(1, 1, 1), status = c(1, 2, 3)), row.names = c(NA, 
  -3L), class = "data.frame", vars = c("year", "status"), drop = TRUE, .Names 
  = c("year", 
  "status")))
  </code></pre>
  
  <p>In theory it's supposed to work like this: </p>
  
  <p>X would get this: </p>
  
  <pre><code>[1] 3.128440 3.333333 3.600000 3.296296 4.000000 4.000000 4.000000 4.234131 
  4.254562 4.386861 4.090909 4.387218
  </code></pre>
  
  <p>Y would get this: 
      [1] 2.703704 2.428571 2.400000 3.034483 3.500000 2.666667 4.000000 3.856167 
      4.045455 3.825000 3.818182 3.996377</p>
  
  <p>and then my Z would get this:</p>
  
  <pre><code>1  3.128440 2.703704
  2  3.333333 2.428571
  3  3.600000 2.400000
  4  3.296296 3.034483
  5  4.000000 3.500000
  6  4.000000 2.666667
  7  4.000000 4.000000
  8  4.234131 3.856167
  9  4.254562 4.045455
  10 4.386861 3.825000
  11 4.090909 3.818182
  12 4.387218 3.996377
  </code></pre>
  
  <p>when i run it however, it says in the app:
      "Error: Results must have length 2, not 0."</p>
  
  <p>When i make a selection on the variables to plot it changes to:
      "Error: Results must have length 1, not 0."</p>
  
  <p>I'm wondering if it has anything to do with if there's no input selected and the error throws because the filter grabs the user input. But if that was the case, I'd think that making selections in all input areas would at least give a plot for that - but it doesn't. If this is what I'm doing wrong, I have no idea where to start... any help would be appreciated!</p>
  
  <p>Any inputs/ideas on how I can get this code to work? THANKS!!!!</p>