在Shiny中使用ggplot

时间:2015-08-13 15:42:19

标签: r ggplot2 shiny

我的数据框如下所示:

publishers
          Publisher       Date        Number    Number2
            A         2015-08-01   2602777.0     3.4
            B         2015-08-01    255545.0     5
            C         2015-08-01      4951.0     6 
            A         2015-08-02    417117.1     7
            B         2015-08-02    256715.0     8
            C         2015-08-02       118.0     9

我想用ggplot创建一个闪亮的图形。所以这是我到目前为止所做的,并且有一个错误:

# ui.R
library(shiny)

shinyUI(fluidPage(
    titlePanel("Title"),
    sidebarLayout(
        sidebarPanel(
            helpText("Text"),
            selectInput("var", 
                label = "Choose a variable to display",
                choices = c("A", "B", "C"),
                selected = "A"),

            mainPanel(plotOutput("map"))
        )
    )
))

# server.R
library(shiny)
library(ggplot2)
publishers <- read.csv("data/syndicationshiny.csv")
source("helpers.R")
head(publishers)
publishers$Date<-as.Date(publishers$Date,'%m/%d/%Y')


shinyServer(
  function(input, output) {
    output$map <- renderPlot({
      data <- switch(input$var, 
            "A" = publishers[ which(publishers$Publisher=='A'),],
            "B" = publishers[which(publishers$Publisher=='B'),],
            "C" = publishers[ which(publishers$Publisher=='C'),]),
      color <- switch(input$var, 
                      "A" = "darkgreen",
                      "B" = "black",
                      "C" = "darkorange")

      legend <- switch(input$var, 
                       "A" = "A",
                       "B" = "B",
                       "C" = "C"),

      ggplot(var,aes(x=Date,y=Number) 
                  color = color, 
                  legend.title = legend)+geom_line()
    })
  }
)

我收到的错误是: sidebarLayout出错(sidebarPanel(helpText(“Text”),:   参数“mainPanel”缺失,没有默认值

我认为我的问题出在ggplot中。

如果有人对这有什么问题有任何想法,那将会非常有帮助。感谢。

0 个答案:

没有答案