title: Shiny Conditional Statements
body: <p>I am having problems using conditional statements in Shiny.  I wan the user to be able to select data for the Y values and it will change the type of chart displayed.  When the type of data is numeric the chart displays fine. But when the type of data is text I want the chart to change to a histogram and just count the number of instances. The two scenarios I am working with are contract spending in the selected category vs the number of contracts in the selected category.  my server code is below.  I just need to be able to switch the type of graph from bar to histogram based on the value selected.</p>
  
  <pre><code>library(shiny)
  library(ggplot2)
  
  shinyServer(function(input, output) {
  spend &lt;- read.csv("C:/Users/William/Documents/First_Rstudio/App-1/data/CENTCOMdata.csv")
  output$GovSpend &lt;- renderPlot({
      spend &lt;- spend[spend$Contracting.Agency.Name == input$agency,]
  
  if(typeof(input$yval) = "double"){ggplot(spend, aes_string(x = input$xlab, y = ylab fill = "Tier.1.Contract.Category")) + 
          geom_bar(na.rm = TRUE, stat= "identity")
      }    
  else {ggplot(spend, aes_string(x = input$xlab, fill= "Tier.1.Contract.Category")) + 
          geom_bar()}
  })
  })
  </code></pre>
  
  <p>Each graph works fine on it's own.  I just can't get the if statement to work. When it renders to the web, it always defaults to the histogram regardless of the data type selected for the yval or which comes first in the if statement.</p>
  
  <p>the UI is here:</p>
  
  <pre><code>library(shiny)
  spend &lt;- read.csv("C:/Users/William/Documents/First_Rstudio/App-1/data/CENTCOMdata.csv")
  shinyUI(fluidPage(
  
  titlePanel("All Gov't Spend"),
  
      sidebarLayout(
  
       sidebarPanel( 
          selectInput("xlab", label = "Select X Values",
                  choices = colnames(spend),
          selected = "FY"
                  ),
  
          selectInput("yval", label = "Select y Values",
                      choices = colnames(spend),
                  selected = "Action_Absolute_Value"
          ),
  
      selectInput("agency", label = "Select Agency",
                  choices = levels(spend$Contracting.Agency.Name)
                  ),
          selectInput("Country", label = "Select Country",
                  choices = levels(spend$Principal.Place.of.Performance.Country.Name))
  
  ),
  
      mainPanel(plotOutput("GovSpend")
  )
  )
  ))
  </code></pre>