R - 时间序列图仅显示在控制台中,但不显示在Web应用程序中

时间:2018-06-15 07:20:38

标签: r shiny

我试图编写一个简单的RShiny应用程序,这是代码:

library(shiny)
library(dplyr)
library(rAmCharts)

source("C:\\Users\\wluo\\Desktop\\Garch\\app\\curncy basket.R")
ui <- fluidPage(mainPanel(plotOutput(outputId = "weight.plot"))

server <- function(input, output) {
        output$weight.plot <- renderPlot({
        date <- as.POSIXct(index(elasticd.w))
       amTimeSeries(data.frame(date, coredata(elasticd.w)), "date", c("CNH", "NTN", "SGD", "EUR", "JPY"),
                    groupToPeriods = c('hh', 'DD', '10DD'), main = "weights", legend = T, precision = 2)
      })
    }
shinyApp(ui = ui, server = server)

运行应用程序时,amTimeSeries生成的绘图在RStudio中显示良好,但Web应用程序为空白。无法弄清楚为什么......提前致谢!

1 个答案:

答案 0 :(得分:0)

您必须使用rAmCharts的特定渲染和输出功能renderAmChartsamChartsOutput)。它不适用于plotOutput。

library(shiny)
library(dplyr)
library(rAmCharts)

# source("C:\\Users\\wluo\\Desktop\\Garch\\app\\curncy basket.R")
data('data_stock_2')

ui <- fluidPage(mainPanel(
  # plotOutput(outputId = "weight.plot"))
  amChartsOutput("weight.plot", height = "600px")
  ))


server <- function(input, output) {
  output$weight.plot <- renderAmCharts({
    # date <- as.POSIXct(index(elasticd.w))
    # amTimeSeries(data.frame(date, coredata(elasticd.w)), "date", c("CNH", "NTN", "SGD", "EUR", "JPY"),
    #              groupToPeriods = c('hh', 'DD', '10DD'), main = "weights", legend = T, precision = 2)
    amTimeSeries(data_stock_2, 'date', c('ts1', 'ts2'))
  })
}

shinyApp(ui = ui, server = server)