【问题标题】:Shiny and ggplot - trouble making the group= reactive闪亮和ggplot - 使组=反应的麻烦
【发布时间】:2014-12-05 05:58:25
【问题描述】:

第一次发帖,第一次使用 Shiny 和 ggplot2,请多多包涵。我无法让 ggplot 将 input$variable 解释为 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))
  })  
})

【问题讨论】:

  • plotOutput("plot") 后面好像多了一个逗号。如果删除多余的逗号后仍然无法正常工作,您应该发布一些示例数据,以便我们为您提供帮助。

标签: r ggplot2 shiny


【解决方案1】:

尝试使用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))
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多