title: Subset a data frame based on user-input, Shiny
body: <p>I'm trying to build a Shiny app that subsets a data frame (to only include rows where a categorical variable matches the user-select input from the UI) before the data is processed in Server and then visualized in the UI. I've tried several different methods but I keep getting errors, e.g. "object of type 'closure' is not subsettable"</p>
  
  <p>Then when I try to cast the reactive user input with </p>
  
  <pre><code>target &lt;- toString(reactive({input$value}))
  </code></pre>
  
  <p>I get the following error:</p>
  
  <p>"Error in as.vector(x, "character") : cannot coerce type 'closure' to vector of type 'character'"</p>
  
  <p>Any ideas? I think there is something conceptual that I'm missing. Here is my code:</p>
  
  <pre><code>#Server
  shinyUI(pageWithSidebar(
  
  headerPanel("Pricing Analysis Tool"),
  
  sidebarPanel(
  selectInput("fruit", "Select fruit:", 
              choices = c(inventory), selected = "banana", multiple = FALSE),
  numericInput("delta", "Price Change (%):", 10),
  submitButton("Run Simulation")),
  
  mainPanel(
  plotOutput("PricePlot")
  )))
  
  
  #server
  shinyServer(function(input, output, session) {
  
  target_inventory &lt;- reactive({inventory$product == input$fruit})
  ...
  
  })
  </code></pre>
  
  <p>Once my inventory data is subset to only include the product I'm evaluating then I will use renderPlot to generate graphs. I'm getting hung up on subsetting based on a user input. Is there some other method I should use to dynamically subset the larger data set based on a user input?</p>
  
  <p>Thanks so much for your help,
  Noah</p>
  
  <p>Update: I was able to successfully subset my data based on variable user inputs and then manipulate the subset and visualize it using this code in my server file (thank you, nivangio, for posting your code which I used as a template on R-blogger: <a href="http://www.r-bloggers.com/dashboards-in-r-with-shiny-and-googlevis/" rel="noreferrer">http://www.r-bloggers.com/dashboards-in-r-with-shiny-and-googlevis/</a>)</p>
  
  <pre><code>target_inventory &lt;- reactive({
      a &lt;- subset(inventory, inventory$product %in% input$fruit)
      a &lt;- droplevels(a)
  return(a)
  })
  </code></pre>
  
  <p>Once the subset was created, I was able to use it in dynamic graphs by referencing it as target_inventory()</p>