使用quantmod和google finance绘制给定时间和货币的货币

时间:2014-06-13 15:58:57

标签: r plot currency shiny quantmod

我的ui.r

library(shiny)

codes <- paste("CURRENCY:",currencies,sep="")
currencies <- c("ARS","AUD","BRL","CAD","CHF",
            "CNY","DKK","EUR","GBP","IDR",
            "ILS","INR",  "JPY","MXN","MYR",
            "NOK","NZD","PHP","RUB","SEK",
            "THB","TRY")

shinyUI(fluidPage(
  titlePanel("Currency Charts"),

  sidebarLayout(
    sidebarPanel(
      helpText("Select a currency to examine. 
        Information will be collected from Quandl."),

      selectInput("symb", 
              label = "Choose a variable to display",
              choices = currencies,
              selected = "ARS"),

      dateRangeInput("dates", 
        "Date range",
        start = "2013-01-01", 
        end = as.character(Sys.Date())),

      actionButton("get", "Get Currency"),

      br(),
      br(),

    )

mainPanel(plotOutput("plot"))
 )
))

server.r

library(quantmod)

shinyServer(function(input, output) {

  output$plot <- renderPlot({
    data <- getSymbols(input$symb, src = "google", 
       from = input$dates[1],
       to = input$dates[2],
       auto.assign = FALSE)

    chartSeries(data, theme = chartTheme("white"), 
      type = "line", TA = NULL)
  })

})

问题:我在第35行遇到意外的符号错误。

我基本上复制了Shiny R给出的示例代码,但我试图使用他们来自雅虎的股票信息图,改为使用google来绘制货币。 CURRENCY:XYZ在谷歌财务中给出了XYZ / USD,这就是ui.r的第一部分。我认为问题在于我使用了getSymbol()和renderPlot()。有什么建议/修正吗?

1 个答案:

答案 0 :(得分:1)

你似乎有2个逗号放错了地方

  1. 删除第二个br()之后的逗号,因为它是sidebarPanel的最后一个元素
  2. 在sidebarPanel的结束圆括号后添加逗号
  3. 所以这个修改过的函数应该这样做:

                library(shiny)
    
                currencies <- c("ARS","AUD","BRL","CAD","CHF",
                                "CNY","DKK","EUR","GBP","IDR",
                                "ILS","INR",  "JPY","MXN","MYR",
                                "NOK","NZD","PHP","RUB","SEK",
                                "THB","TRY")
    
                codes <- paste("CURRENCY:",currencies,sep="")
    
                shinyUI(fluidPage(
                  titlePanel("Currency Charts"),
    
                  sidebarLayout(
                    sidebarPanel(
                      helpText("Select a currency to examine. 
                               Information will be collected from Quandl."),
    
                      selectInput("symb", 
                                  label = "Choose a variable to display",
                                  choices = currencies,
                                  selected = "ARS"),
    
                      dateRangeInput("dates", 
                                     "Date range",
                                     start = "2013-01-01", 
                                     end = as.character(Sys.Date())),
    
                      actionButton("get", "Get Currency"),
    
                      br(),
                      br()
    
                    ),
    
                    mainPanel(plotOutput("plot"))
                  )
                ))