闪亮的应用程序时间序列图与数据表

时间:2017-06-23 09:12:46

标签: r shiny

我正在尝试构建一个简单的Shiny应用程序,它可以从CSV文件中获取数据,然后显示数据和图表,这是我写的R代码,

require(graphics) 
shinyServer(function(input, output) {

#This function is repsonsible for loading in the selected file
filedata <- reactive({
infile <- input$datafile
    if (is.null(infile)) {
# User has not uploaded a file yet
      return(NULL)
      data <- read.csv(inFile$datapath)
      data
    }
    read.csv(infile$datapath)

  })


  #This previews the CSV data file
  output$filetable <- renderTable({
    filedata()
  })

  #Plot time Series plot
  output$tsplot <- renderPlot({
    x <- as.numeric(filedata)
    ts.obj <- ts(x)
    lowess.obj <- lowess(ts.obj, f = 10)
    plot.ts(x, main = "Sample Time Series", xlab = "Time")
    points(x)
    lines(lowess.obj$y, col = "red")
    legend("top", legend = "Loess Smoother", col = "red", lty = 1)
  })

但是当我运行这个时,我得到一个错误'错误:不能强制类型'封闭'到'double'类型的向量',无法弄清楚出了什么问题

1 个答案:

答案 0 :(得分:0)

也许你会这么想:

 output$tsplot <- renderPlot({
        x <- as.numeric(filedata())### call the data file with parenthesis
        ts.obj <- ts(x)
        lowess.obj <- lowess(ts.obj, f = 10)
        plot.ts(x, main = "Sample Time Series", xlab = "Time")
        points(x)
        lines(lowess.obj$y, col = "red")
        legend("top", legend = "Loess Smoother", col = "red", lty = 1)
      })