2017-03-16 75 views
0

我對此很新,所以可能有一個簡單的解釋。我正在處理一組水質觀測數據。它開始像建築用閃亮的錯誤

Sample.ID,Sample.Date,Beach.Name,Sample.Location,Results,Units 
050514CP13,5/5/2014,MIDLAND BEACH,Center,20,MPN/100 ml 
062011GR04,6/20/2011,MANHATTAN BEACH,Left,0,MPN/100 ml 
072808BH09,7/28/2008,MIDLAND BEACH,Right,28,MPN/100 ml 
051214CP36,5/12/2014,SOUTH BEACH,Right,4,MPN/100 ml 
081511KB07,8/15/2011,CEDAR GROVE,Left,360,MPN/100 ml 
062909KB01,6/29/2009,MANHATTAN BEACH,Left,8,MPN/100 ml 
082112KB07,8/21/2012,CEDAR GROVE,Left,20,MPN/100 ml 

我有以下ui.R

library(shiny) 

beaches <- read.csv("BeachWaterQuality.csv", header = TRUE) 
beachNames <- levels(beaches$Beach.Name) 
new.date <- strptime(beaches$Sample.Date, format="%m/%d/%Y") 
minDate <- min(new.date) 
maxDate <- max(new.date) 


shinyUI(fluidPage(

    # Application title 
    titlePanel("Beach Water Quality History"), 

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
    sidebarPanel(
     selectInput("beach", 
        label = "Choose a beach to display", 
        choices = beachNames), 

     selectInput("sampleLocation", 
        label = "Choose a sample location", 
        choices = list("LEFT","CENTER", "RIGHT"), 
        selected="CENTER"), 


     dateRangeInput("dates", 
        label= "Choose a date range to display", 
        start=minDate, 
        end=maxDate) 
    ), 

    # Show a plot of the selected data 
    mainPanel(
     plotOutput("beachDataPlot") 
    ) 
) 
)) 

這server.R

library(shiny) 

shinyServer(function(input, output) { 

    beaches <- read.csv("BeachWaterQuality.csv", header = TRUE) 
    beaches$Results[is.na(beaches$Results)] <- 0 
    beachNames <- levels(beaches$Beach.Name) 
    new.date <- strptime(beaches$Sample.Date, format="%m/%d/%Y") 
    beaches <- cbind(beaches,new.date) 


    output$beachDataPlot <- renderPlot({ 

    plotData <- subset(beaches, Beach.Name==input$beach & Sample.Location==input$sampleLocation) 


    plot(x=plotData$new.date, 
     y=plotData$Results, 
     xlab="Date", 
     ylab="Bacterial Count", 
     pch=16, 
     main=paste("Bacterial Count for",input$beach,input$sampleLocation)) 
    lines(plotData$new.date,plotData$Results,col="red") 
    }) 
}) 

當我試圖運行此我的應用得到一個錯誤窗口說

Error: need finite 'xlim' values

而在t他控制檯

Warning in min(x) : no non-missing arguments to min; returning Inf 
Warning in max(x) : no non-missing arguments to max; returning -Inf 
Warning in min(x) : no non-missing arguments to min; returning Inf 
Warning in max(x) : no non-missing arguments to max; returning -Inf  
Warning: Error in plot.window: need finite 'xlim' values Stack trace (innermost first): 
     103: plot.window 
     102: localWindow 
     101: plot.default 
     100: plot 
     99: renderPlot [C:\Users\jerem\YuckyBeach/server.R#30] 
     89: <reactive:plotObj> 
     78: plotObj 
     77: origRenderFunc 
     76: output$beachDataPlot 
      1: runApp 

有人能指出我在做什麼錯嗎?

+0

'plotData'的行數是多少?是0嗎?我得到了類似的錯誤,使用以下代碼:'plotData < - subset(beach,Beach.Name ==「SOUTH BEACH」&Sample.Location ==「Left」)'then'plot(x = plotData $ new.date,y = plotData $結果)' – kitman0804

回答

0

它甚至比那更笨!在ui.R中,我將位置選項設置爲LEFT,CENTER和RIGHT ...全部大寫,因爲這是海灘名稱的存儲方式。但在數據中的位置是左,中,右...所以子集()返回一個空的數據幀...

0

如果我嘗試了一個快速的猜測,我會說這有什麼做的「閃亮」的一部分,而是與線

beaches <- cbind(beaches,new.date) 

我覺得用「cbind」,而不是「 data.frame」做奇怪的事情對類數據,引起功能陰謀拋出一個錯誤...也許嘗試與data.frame更換cbind,如果它仍然無法正常工作,請嘗試:

print(beaches) 

在renderPlot塊內,查看你的數據是什麼樣的...