Shiny App Time Series plot with data table
我正在尝试构建一个简单的 Shiny 应用程序,它可以从 CSV 文件中获取数据输入,然后将数据与绘图一起显示,这是我编写的 R 代码,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 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) }) |
但是当我运行它时,我收到一个错误"错误:无法将类型"闭包"强制转换为"双"类型的向量,无法找出问题所在
也许你应该试试这个:
1 2 3 4 5 6 7 8 9 | 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) }) |