【问题标题】:R Shiny - Error : "Found object is not a position"R Shiny - 错误:“找到的对象不是位置”
【发布时间】:2016-11-21 04:23:39
【问题描述】:

当我在本地运行闪亮的应用程序时,fine 一切正常。但是,当我部署它时,我收到一条错误消息,上面写着“警告:错误:找到的对象不是位置”。和the app 不起作用。我尝试了所有我发现的东西,包括创建一个 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")
  )
 )
)

【问题讨论】:

  • 您的单选按钮为您提供了一个数值,但您的开关将数字作为字符引用。当您引用单选按钮值或取消引用开关时会发生什么?
  • 当我更改它们时,它给了我同样的错误。我在想这是关于上传 rds 数据文件的,但是我可以在 shinyapps 服务器中看到该文件。
  • shinyapps 服务器中的 rds-file 文件夹是否为 data? (只是为了确定)
  • 是的,它的名字是“数据”。

标签: r shiny


【解决方案1】:

原来直方图中的密度图会导致错误。没有密度图也能正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-05
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-29
    相关资源
    最近更新 更多