【问题标题】:Plotting currencies given time and currency using quantmod and google finance使用 quantmod 和 google Finance 绘制给定时间和货币的货币
【发布时间】:2014-08-04 06:15:19
【问题描述】:

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

服务器.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 给出的示例代码,但我正在尝试使用他们从 yahoo 获取的股票信息图,而不是使用 google 并绘制货币图。 CURRENCY:XYZ 在谷歌金融中给出 XYZ/USD,这就是 ui.r 的第一部分。我认为问题在于我对 getSymbol() 和 renderPlot() 的使用。有什么建议/修复吗?

【问题讨论】:

标签: r plot currency shiny quantmod


【解决方案1】:

你好像有两个逗号放错了

  1. 删除第二个 br() 后的逗号,因为它是 sidebarPanel 的最后一个元素
  2. 在侧边栏面板的右圆括号后添加逗号

所以这个修改后的函数应该这样做:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    相关资源
    最近更新 更多