首次发布和第一次使用Shiny和ggplot2,所以请耐心等待。我无法让ggplot将输入$变量解释为group =选项的值。我已经在SO post中找到了一些指导,但无法让它发挥作用。我已经在下面粘贴了我的代码的简化版本,这会产生一个未找到的输入"错误。任何想法如何解决?
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))
})
})
答案 0 :(得分:2)
尝试使用aes_string()
代替aes()
,以便正确评估input$dim
:
output$plot <- renderPlot({
ggplot(subscriptions, aes(x = season)) +
geom_freqpoly(aes_string(x = "season", group=input$dim, colour=input$dim))
})