【问题标题】:Shiny App - Having trouble plotting a stock line chartShiny App - 无法绘制股票折线图
【发布时间】:2020-12-09 10:32:40
【问题描述】:

我正在尝试在闪亮的应用程序中使用 quantmod 绘制股票折线图。 收到错误。 警告:sourceUTF8 中的错误:错误采购 /home/ccc_v1_w_62aa8_36923/asn122362_7/asn122367_1/Dashboard 4Dec/9 Dec Stock APP TESTING/Testing Stock App/server.R [没有可用的堆栈跟踪] sourceUTF8(serverR, envir = new.env(parent = sharedEnv)) 中的错误:

Server.R
library(quantmod)
shinyServer(function(input, output){
  price <- getSymbols(input$stockInput,
                                  type="line",
                                  from='2019',
                                  theme=chartTheme('white'),
                      auto.assign = F)
                      plot(price, main = input$stockInput)})

ui.R
library(shiny)

shinyUI(fluidPage(
  titlePanel("Stock Chart"),
  sidebarLayout(
    sidebarPanel(
      
      #This is a dropdown to select the stock
      selectInput("stockInput", 
                  "Pick your stock:", 
                  c("AMZN","FB","GOOG","NVDA","AAPL"),
                  "AMZN"),selected = "GOOG"),
    
    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("distPlot")
    ))))

【问题讨论】:

  • getSymbol 崩溃了,您也无法使用此功能获取价格数据...
  • 谢谢。有什么建议吗?

标签: r shiny quantmod


【解决方案1】:

试试这个

library(quantmod)
server <- shinyServer(function(input, output){
  observe({
  price <- getSymbols(req(input$stockInput),
                      type="line",
                      from="2015-01-01",to="2016-01-01",
                      theme=chartTheme('white'),
                      auto.assign = F)
  output$distPlot <- renderPlot({
    plot(price, main = req(input$stockInput))
  })
  })
})

### ui.R
library(shiny)

ui <- shinyUI(fluidPage(
  titlePanel("Stock Chart"),
  sidebarLayout(
    sidebarPanel(

      #This is a dropdown to select the stock
      selectInput("stockInput",
                  "Pick your stock:",
                  choices = c("AMZN","FB","GOOG","NVDA","AAPL"),
                  selected = "GOOG")
      ),

    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("distPlot")
    )
    )))

shiny::shinyApp(ui, server)

【讨论】:

  • 感谢您的回复。看起来它不起作用。出现错误:警告:getSymbols.yahoo 中的错误:无法导入“AAPL”。字符串不是标准的明确格式 48:停止 47:getSymbols.yahoo 45:getSymbols
  • @Trungle83,请再试一次。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-01
  • 2014-08-26
  • 2016-05-10
  • 2016-07-31
  • 1970-01-01
相关资源
最近更新 更多