R Shiny - 错误:“发现对象不是位置”

时间:2016-11-19 00:15:04

标签: r shiny

当我在本地运行闪亮的应用程序时,一切正常fine。但是当我部署它时,我收到一条错误,上面写着“警告:错误:找到对象不是位置”。而the app不起作用。我试过everthing,我发现包括创建一个global.R文件,读取ui等数据。但它仍然是相同的。感谢您的帮助。

以下是代码:

server.R

library(shiny)
library(ggplot2)
grindelwald_data <- readRDS("data/data.rds")
server <-shinyServer(
function(input, output,session) {

grindelwald_data$Date<-as.Date(grindelwald_data$Date, format="%d/%m/%Y")
grindelwald_data$Month <- as.factor(format(as.Date(grindelwald_data$Date),"%m"))
grindelwald_data$Year <- format(grindelwald_data$Date,format="%Y")

annual_mean_precipitation<-aggregate( Precipitation ~ Year , grindelwald_data , sum)
annual_mean_temperature<-aggregate( Temperature ~ Year , grindelwald_data , mean)
annual_mean_discharge<-aggregate( Discharge ~ Year , grindelwald_data , mean)
annual_mean_discharge<-annual_mean_discharge[!(annual_mean_discharge$Discharge<5),]  

output$value <- renderPrint({ input$radio })  



output$distPlot <- renderPlot({
  dist <- switch(input$dist,
                 "1" = annual_mean_precipitation$Precipitation,
                 "2" = annual_mean_temperature$Temperature,
                 "3" = annual_mean_discharge$Discharge
  )

  x    <- dist     
  # draw the histogram with the specified number of bins
  switch(input$dist,
         "1" = updateSliderInput(session, "bins", min=1,max=100,step= 1),
         "2" = updateSliderInput(session, "bins",min=0.01,max=0.7,step= 0.01),
         "3" = updateSliderInput(session, "bins",min=0.01,max=2,step= 0.01)
  )

  switch(input$dist,
         "1" = ggplot(annual_mean_precipitation, aes(x=x))+
           geom_histogram(aes(y=..density..),binwidth=input$bins,colour="white", fill="#56B4E9") +
           geom_density(alpha=.2,colour="#CC79A7",size=1, fill="#FF6666")+
           labs(title="Histogram of the  Annual Mean Precipitation with Density",x="Precipitation (mm)",y="Density"),

         "2" = ggplot(annual_mean_temperature, aes(x=x))+
           geom_histogram(aes(x=x,y=..density..),binwidth=input$bins,colour="white", fill="#F0E442") +
           geom_density(alpha=.2,colour="#CC79A7",size=1, fill="#FF6666")+
           labs(title="Histogram of the  Annual Mean Temperature with Density",x="Temperature (C)",y="Density"),
         "3" = ggplot(annual_mean_discharge, aes(x=x))+
           geom_histogram(aes(x=x,y=..density..),binwidth=input$bins,colour="white", fill="#0072B2") +
           geom_density(alpha=.2,colour="#CC79A7",size=1, fill="#FF6666")+
           labs(title="Histogram of the  Annual Mean Discharge with Density",x="Discharge (m3/s)",y="Density")
    )
  })

 }
)

ui.R

ui<-fluidPage(
# Application title
titlePanel("Histogram-Luetschine River"),
radioButtons("dist", label = "",
           choices = list("Precipitation" = 1, "Temperature" = 2,    "Discharge" = 3), 
           selected = 1),


sidebarLayout(
sidebarPanel(
  sliderInput("bins",
              "Number of Bins:",
              min = 1,
              max = 100,
              value = 17)
),


mainPanel(
  plotOutput("distPlot")
  )
 )
)

1 个答案:

答案 0 :(得分:0)

直方图中的密度图导致错误。没有密度图,它工作正常。