错误:至少一个图层必须包含用于构面的所有变量R Shiny App

时间:2017-10-26 17:19:46

标签: r ggplot2 shiny

运行我的Shiny App时出现以下错误。

  

至少有一个图层必须包含用于构图的所有变量

Image File for Error

我经历了一些有关此问题的答案,但是没有一个选项可行,例如将facet_wrap更改为facet_grid。

app.R文件:

library(shiny)
library(ggplot2)
library(lubridate)

AorData <- read.csv(file="E:\\DrWheeler\\DataManipulation\\AoristicEstimates.csv",
                    header=TRUE)
AorData$HourF <- hour(hms(AorData$Hour))
AorData$WkDay <- factor(AorData$Week, levels=1:7, labels=c('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'))


server <- function(input, output) {

  act1 <- reactive({
    AorData[,input$Location]
  })

  act2 <- reactive({
    AorData[,input$Crime]
  })

  subdata <- reactive(function(act2,act1){
    subset(AorData, ucr_redString == act2 & RedLoc == act1)
  })

  output$data <- renderPlot({
      ggplot(data= subdata(), aes(x=HourF, y=per_aor, group=WkDay)) + 
      geom_line(size=1.05) +  
      geom_point(shape=21,fill="black",color="white", size=3.5, stroke=1.7) +
      facet_wrap( ~ WkDay)})
}

ui <- fluidPage(

  titlePanel("Aoristic Estimate"),

  sidebarLayout(
    sidebarPanel(
      selectInput("Location", "LOCATION", AorData$RedLoc),
      selectInput("Crime", "CRIME", AorData$ucr_redString)
    ),

    mainPanel(
      plotOutput("data")
    )
  )

)

shinyApp(ui=ui, server= server)

链接到数据:https://www.dropbox.com/s/0yg3n2nfmmvr140/AoristicEstimates.csv?dl=0

当我独立运行时,情节完美无缺。但是在app中不起作用。

Image of resultant plot

有人可以帮我这个吗?我一直在关注构建这个应用程序的教程,因此我可能会错过一个基本步骤。

非常感谢!

0 个答案:

没有答案
相关问题