2017-03-16 19 views
0

私はこれでかなり新しいので、おそらく簡単な説明があります。私は、水質観測のデータセットを使って作業しています。それはShinyを使ってプロットをビルドする際のエラー

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

そして、彼はコンソール

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.Name ==" SOUTH BEACH "&Sample.Location ==" Left ")'次に 'plot(x = plotData $ new.date、y = plotData $ Results) ' – kitman0804

答えて

0

それはそれ以上の数です! ui.Rでは、私は左、中央、右のように場所の選択肢を設定しています...すべての帽子はビーチの名前がどのように格納されるかです。しかし、そのデータは左、中央、右の位置にあるので、サブセット()は空のデータフレームを返していました...

0

私はちょうど迅速な推測を試みた場合、私はそれが "「シャイニー」の部分ではなく、むしろ

beaches <- cbind(beaches,new.date) 

は、私が「CBIND」の使用を考える代わりのラインとは何の関係もありませんでしょうねdata.frame」エラーをスローする機能プロットを引き起こし、あなたのデータのクラスに奇妙なことを行います...たぶんdata.frameでCBIND交換してみてください、そして、それはまだ動作しない場合は、試してみてください。

print(beaches) 
renderPlotブロック内の

は、あなたのデータがどのように見えるかを確認します。

関連する問題