title: Shiny/ggvis Reactivity to Subset Plot Data
body: <p>After seeing a talk on GGVIS, I have been trying my hand unsuccessfully at creating my first Shiny/ggvis app. My plot works in R, but when I try to migrate it into a Shiny app for display on the web I get nothing. The radio buttons are displayed and from what I can tell seem to be working (I tested using the table from rStudio/Shiny/Reactivity tutorial, but it doesn't seem to place nice with my ggvis plot). I have been following the tutorials on Rstudio and using pieces from the demo folder in the ggvis source code. I am trying to create a simple kernel density plot that subsets data based on user input and displays the distribution. Attached is a reproducible example of what I have thusfar. I would appreciate any insight as to what I am missing here.</p>
  
  <h3>ui.R</h3>
  
  <pre><code># clear memory &amp; load packages
        rm(list=ls())
  
        library(shiny)
        library(ggvis)
  
  # Define UI for distribution application
      shinyUI(fluidPage(
  
  # Application title
           titlePanel("Diamond Carats by Color/Cut"),
  
  # Sidebar with controls to select subset
            sidebarLayout(
            sidebarPanel(
              radioButtons("cut", "Diamond Cut:",
                           c("Ideal" = "IDEAL",
                             "Premium" = "IDEAL",
                             "Good" = "GOOD",
                             "Very Good" = "VGOOD"))
            ),
  
  #  Display your plot created by GGvis        
              mainPanel(ggvis_output("my_plot"))
  
            )
          ))
  </code></pre>
  
  <hr>
  
  <h3>server.R</h3>
  
  <pre><code># clear memory &amp; load packages    
          rm(list=ls())
  
          library(shiny)
          library(ggvis)
  
  # Define server logic for distribution application
  
          shinyServer(function(input, output, session) {
  
  # load your data      
            dataset &lt;- diamonds
  
  # Reactive expression to generate the subset.      
            datasetInput &lt;- reactive({                
              selection &lt;-switch(input$cut,
                                 IDEAL = "Ideal",
                                 PREM = "Premium",
                                 GOOD = "Good",
                                 VGOOD = "Very Good") 
  
              subset(dataset, cut == selection)                   
            })
  
  
  # Generate your plot using GGvis and your reactive inputs      
            gv &lt;- reactive({
  
              ggvis(datasetInput(), by_group(color),
                    props(x = ~carat,
                          stroke = ~color,
                          fill = ~color,
                          fillOpacity := 0.2,
                          fillOpacity.hover := 0.7)) +
                layer_density()                                
            })
  
  
  # necessary additions for ggvis integration to shiny        
            output$controls &lt;- renderControls(gv)
            observe_ggvis(gv, "my_plot", session)               
          })
  </code></pre>
  
  <p>EDIT: To follow up on this question, I have noticed that if I remove the following:</p>
  
  <pre><code>            by_group(color)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>            stroke = ~color, 
              fill = ~color,
  </code></pre>
  
  <p>from my call to create the graph in server.R, the graph runs (albeit without the multicolored groupings, which is what I was after in the first place)  and the radio buttons successfully select my data subset. As mentioned, when I am just running the graph in R, without the use of the reactive subsetting function, the graph is able to run and vary the stroke/fill by diamond color. Is this feature currently not supported in Shiny to ggvis interaction at this time? Or am I just misinterpreting this function somehow? Here is my updated code, so you can see my result:</p>
  
  <h3>ui.R</h3>
  
  <pre><code># clear memory &amp; load packages
        rm(list=ls())
  
        library(shiny)
        library(ggvis)
  
  # Define UI for distribution application
      shinyUI(fluidPage(
  
  # Application title
           titlePanel("Diamond Carats by Color/Cut"),
  
  # Sidebar with controls to select subset
            sidebarLayout(
            sidebarPanel(
              radioButtons("cut", "Diamond Cut:",
                           c("Ideal" = "IDEAL",
                             "Premium" = "IDEAL",
                             "Good" = "GOOD",
                             "Very Good" = "VGOOD"))
            ),
  
  #  Display your plot created by GGvis        
              mainPanel(ggvis_output("my_plot"))
  
            )
          ))
  </code></pre>
  
  <hr>
  
  <h3>server.R</h3>
  
  <pre><code># clear memory &amp; load packages    
          rm(list=ls())
  
          library(shiny)
          library(ggvis)
  
  # Define server logic for distribution application
  
          shinyServer(function(input, output, session) {
  
  # load your data      
            dataset &lt;- diamonds
  
  # Reactive expression to generate the subset.      
            datasetInput &lt;- reactive({                
              selection &lt;-switch(input$cut,
                                 IDEAL = "Ideal",
                                 PREM = "Premium",
                                 GOOD = "Good",
                                 VGOOD = "Very Good") 
  
              subset(dataset, cut == selection)                   
            })
  
  
  # Generate your plot using GGvis and your reactive inputs      
            gv &lt;- reactive({
  
              ggvis(datasetInput(),
                    props(x = ~carat,
                          fillOpacity := 0.2,
                          fillOpacity.hover := 0.7)) +
                layer_density() 
  
            })
  
  
  # necessary additions for ggvis integration to shiny        
            output$controls &lt;- renderControls(gv)
            observe_ggvis(gv, "my_plot", session)               
          })
  </code></pre>