2

First post and first time using Shiny and ggplot2, so please bear with me. I'm having trouble getting ggplot to interpret an input$variable as a value for a group= option. I've found some guidance in this SO post, but can't quite get it to work. I've pasted a simplified version of my code below, which produces an "input not found" error. Any ideas how to resolve?

ui.r

library(markdown)

shinyUI(navbarPage("Shiny: First App",
        tabPanel("Annual Trends",
                 verticalLayout(
                      titlePanel("Annual Subscriptions Data"),

                      selectInput("dim",
                          label = "Dimension of Interest",
                          choices = c("location", "package",
                                      "section", "price.level", "no.seats"),
                          selected = "location"),

                       plotOutput("plot"),
                      )
               )
    )
)

server.R

library(shiny)
library(ggplot2)

subscriptions = read.csv("data/subscriptions.csv")

shinyServer(function(input, output, session) {

output$plot <- renderPlot({
       ggplot(subscriptions, aes(x = season)) +
       geom_freqpoly(aes(x = season, group=input$dim, colour=input$dim))
  })  
})
Community
  • 1
  • 1
misanuk
  • 125
  • 3
  • 9
  • It looks like you have an extra comma after `plotOutput("plot")`. If it still doesn't work after removing the extra comma, you should post some sample data so we can help you. – shadow Dec 05 '14 at 09:16

1 Answers1

3

Try using aes_string() instead of aes(), so that it will correctly evaluate input$dim:

output$plot <- renderPlot({
   ggplot(subscriptions, aes(x = season)) +
   geom_freqpoly(aes_string(x = "season", group=input$dim, colour=input$dim))
})
mdlincoln
  • 274
  • 3
  • 12