title: how to properly use checkboxInput on Shiny - R code
body: <p>I have a working app that I would like to enhance with a checkboxInput.  </p>
  
  <p>1> Here is a sample of the data:</p>
  
  <pre><code>     StudentID StudentGender GradeName    TermName MeasurementScaleName TestPercentile GoalRITScore1 GoalRITScore2 GoalRITScore3 GoalRITScore4
  1         1374             M         3   Fall 2009              Reading             32           188           181           179            NA
  50        1297             F         8   Fall 2009       Language Usage             48           224           214           209           228
  101       1608             F         8   Fall 2009          Mathematics             40           225           210           211           244
  1500      1286             M         1   Fall 2011       Language Usage             NA           218           225           238           221
  2345      1196             F         8   Fall 2012       Language Usage             78           230           227           239           223
  5498      1376             F         3 Spring 2010              Reading             24           188           194           185            NA
  8954       486             M         2 Spring 2014              Reading              2           146           152           174            NA
  9000       577             F         2 Spring 2014              Reading             71           196           189           207            NA
       GoalRITScore5 GoalRITScore6
  1               NA            NA
  50              NA            NA
  101            233           227
  1500            NA            NA
  2345            NA            NA
  5498            NA            NA
  8954            NA            NA
  9000            NA            NA
  </code></pre>
  
  <p>2> Here is part of the working script.<br>
  Shiny UI</p>
  
  <pre><code>library(shiny)
  shinyUI(navbarPage("MAP results",
  
    tabPanel("Summaries",
  
            sidebarLayout(
  
              sidebarPanel(
                selectInput("testname",           
                            "Select the test to visualize",
                            levels(mapdata$MeasurementScaleName)),
                selectInput("termname",         
                             "Select the term the test was taken",
                             levels(mapdata$TermName)),
                selectInput("ritorpercent",
                            "Display RIT scores or percentiles",
                            choices = c("RIT Scores", "Percentiles")),
                checkboxInput("gender", "Display Gender differences"),
                ),
  
            mainPanel(
              plotOutput("mapgraph")
              )
            )
          ),
  
    tabPanel("Growth visualizations")
          )
  )
  </code></pre>
  
  <p>And part of the Server.R script.</p>
  
  <h1>Server.R</h1>
  
  <pre><code>library(shiny)
  library(dplyr)
  library(tidyr)
  library(ggplot2)
  
  mapdata &lt;- read.csv("MAP data raw.csv")
  
  shinyServer(function(input, output) {
  
    output$mapgraph &lt;- renderPlot({
  
      graph1RIT &lt;- reactive (mapdata %&gt;% 
                               filter(TermName == input$termname, MeasurementScaleName == input$testname) %&gt;% 
                               group_by(GradeName) %&gt;% 
                               summarise(meanPer = mean(TestPercentile)))
      ggplot(graph1RIT(), aes(as.factor(GradeName), meanPer, fill = as.factor(GradeName))) +
        geom_bar(stat="identity") + 
        #coord_cartesian(ylim = c(150, 250)) + 
        labs(x = "Grade Level", y = "Mean RIT Percentile") + 
        guides(fill = FALSE)
  
    })
  })
  </code></pre>
  
  <p>Now I want to use my checkboxInput("gender"), to make the same bargraph but with gender segregation.  ... and I thought I could just add this into the server.r</p>
  
  <pre><code>if(input$gender) {
        graph3RIT &lt;- reactive (mapdata %&gt;% 
                                 filter(TermName == input$termname, MeasurementScaleName == input$testname) %&gt;% 
                                 group_by(GradeName, StudentGender) %&gt;% 
                                 summarise(meanPer = mean(TestPercentile)))
        ggplot(graph3RIT(), aes(as.factor(GradeName), meanPer, fill = as.factor(StudentGender))) +
          geom_bar(stat="identity", position = "dodge") + 
          labs(x = "Grade Level", y = "Mean RIT Percentile")
      }
  </code></pre>
  
  <p>But if I do that, then the first graph doesn't show up anymore.  I've tried to look on the showmeshiny website for similar situation, but all the ones I could find didn't have the code available.  </p>
  
  <p>Any guidance on how I could use that checkbox, to change the graph </p>