问题
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
- remove the comma after your second br(), as it is the last element of sidebarPanel
- 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