Plotting currencies given time and currency using quantmod and google finance

自作多情 提交于 2019-12-11 19:38:31

问题


My 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)
  })

})

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

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?


回答1:


it seem you have 2 commas misplaced

  1. remove the comma after your second br(), as it is the last element of sidebarPanel
  2. add a comma after the closing round bracket of 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"))
              )
            ))


来源:https://stackoverflow.com/questions/24209512/plotting-currencies-given-time-and-currency-using-quantmod-and-google-finance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!