使用Quantmod和谷歌金融绘制给定时间和货币的货币 [英] Plotting currencies given time and currency using quantmod and google finance

查看:100
本文介绍了使用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行不断收到意外的符号错误。

Problem: I keep getting an unexpected symbol error at line 35.

我基本上复制了示例代码Shiny R给出了,但是我试图使用他们从Yahoo获得的股票信息图,改为使用Google并绘制货币。
CURRENCY:XYZ在Google财务中提供XYZ / USD,这就是ui.r的第一部分。我认为问题出在我对getSymbol()和renderPlot()的使用上。

I basically copied the code of the example that Shiny R gives, but I'm trying to use their plot of stock information from yahoo, to use google instead and to plot currencies. CURRENCY:XYZ gives XYZ/USD in google finance, thats what the first part of ui.r is. I think the problem is with my usage of the getSymbol() and renderPlot(). Any suggestions/fixes?

推荐答案

似乎您有2个逗号错位了

it seem you have 2 commas misplaced


  1. 在第二个br()之后删除逗号,因为它是sidebarPanel的最后一个元素

  2. 在sidebarPanel的右圆括号后添加逗号

因此,此修改后的函数应执行以下操作:

So this modified function should do:

            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"))
              )
            ))

这篇关于使用Quantmod和谷歌金融绘制给定时间和货币的货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆