Reputation: 125
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))
})
})
Upvotes: 2
Views: 1334
Reputation: 314
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))
})
Upvotes: 3