title: Shiny ggvis reactive plot
body: <p>I'd like to make <code>Shiny app</code>, which plots cumstom graphs on the parameters i choose using <code>ggvis</code> package.</p>
  
  <p>If I choose All brands, I'd like to get this plot:</p>
  
  <p><a href="https://i.stack.imgur.com/ENIop.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ENIop.png" alt="All brands"></a></p>
  
  <p>But when I select only one specific brand, the plot should look like this:</p>
  
  <p><a href="https://i.stack.imgur.com/eCW1d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eCW1d.png" alt="enter Specific brand"></a></p>
  
  <p>I tried different ways, but none of them gave me results I expected.</p>
  
  <p>Could you please, give an ideas how to solve this issue?</p>
  
  <p>Also I include reproducable example:</p>
  
  <pre><code>library(shiny)
  library(shinydashboard)
  library(plyr)
  library(ggvis)
  
  
  # Header -----------------------------------------------------------
  
  header &lt;- dashboardHeader(title= "DashBoard")
  
  
  # Sidebar --------------------------------------------------------------
  
  sm &lt;- sidebarMenu(
  
    menuItem(
      text="GGVIS",
      tabName="GGVIS",
      icon=icon("eye")
    )  
  
  )
  
  sidebar &lt;- dashboardSidebar(sm)
  
  # Body --------------------------------------------------
  
  body &lt;- dashboardBody(
  
    # Layout  --------------------------------------------  
  
    tabItems(
  
  
      tabItem(
        tabName="GGVIS",
        fluidPage(
  
          fluidRow(
  
            title = "Inputs", status = "warning", width = 2, solidHeader = TRUE, collapsible = TRUE,
  
  
  
            uiOutput("Category"),
            uiOutput("Brand"),
            uiOutput("Values"),
            ggvisOutput("p")
  
  
  
  
  
  
          )
        )
      )
    )
  )
  
  # Setup Shiny app UI components -------------------------------------------
  
  ui &lt;- dashboardPage(header, sidebar, body)
  
  # Setup Shiny app back-end components -------------------------------------
  
  server &lt;- function(input, output) {
  
    set.seed(1992)
    n=101
  
     Letter &lt;- sample(c("a", "b", "c"), n, replace = TRUE, prob = NULL)
     Category &lt;- sample(c("Car", "Bus", "Bike"), n, replace = TRUE, prob = NULL)
     Brand &lt;- sample("Brand", n, replace = TRUE, prob = NULL)
     Brand &lt;- paste0(Brand, sample(1:14, n, replace = TRUE, prob = NULL))
     USD &lt;- abs(rnorm(n))*100
  
     df &lt;- data.frame(Letter, Category, Brand, USD)
  
  
  
    # Inputs --------------------------------------
  
     output$Category &lt;- renderUI({
      selectInput("Category", "Choose category:", 
                  choices = c("Car","Bus", "Bike" ))
    })
  
  
    output$Brand &lt;- renderUI({
  
  df2 &lt;- df[df$Category %in% input$Category,]
  
    selectInput("Brand", 
                  "Brand:", 
                  c("All", unique(as.character(df2$Brand)))) 
    })
  
  
    # ----------------------------------------------------------------------------- 
  
  
  data2 &lt;-  reactive({
  
  
    df &lt;- df[df$Category %in% input$Category,]
    df &lt;- df[df$Brand %in% input$Brand,] # if I comment this line, I get All brands graph
    df &lt;- droplevels(df)  
  
    df &lt;- ddply(df, c("Letter", "Category", "Brand"), summarise, "USD" = sum(USD))
  
  })   
  
  
  data2%&gt;% group_by(Brand) %&gt;%
    ggvis(x = ~factor(Letter, levels = c("a", "b", "c")), y = ~USD, fill =    ~Brand, fillOpacity := 1) %&gt;%
    layer_bars() %&gt;%
    add_axis("x", title = "Letter") %&gt;% bind_shiny("p")
  
  
  
  
  
  
  
    # -----------------------------------------------------------------------------
  
  
  }
  
  # Render Shiny app --------------------------------------------------------
  
  shinyApp(ui, server)
  </code></pre>