簡體   English   中英

如何使此R腳本正常工作

[英]How to get this R script working

我很難理解為什么輸入將不會傳遞到服務器端,無法繼續工作並在繪圖中返回。 我真的希望有人能對UI / SERVER動態工作方式有所啟發。

    library(shiny)
    library(quantmod)
    library(BatchGetSymbols)


    # Define server logic required to draw a histogram
    shinyServer(function(input, output) {

      dataInput <- reactive({
        getSymbols(input$stock, src = "google",
                   auto.assign = FALSE)
      })

    output$plot <- renderPlot({    
      chartSeries(dataInput(), theme = chartTheme("white"))
      addBBands()
      addMACD()
      addRSI()
    })



      })

library(shiny)
library(quantmod)
library(BatchGetSymbols)

first.date <- Sys.Date()-365
last.date <- Sys.Date()

df.SP500 <- GetSP500Stocks()
tickers <- df.SP500$tickers

l.out <- getSymbols(tickers = tickers,
                    first.date = first.date,
                    last.date = last.date)

stocks <- df.SP500[,1]

shinyUI(fluidPage(


  titlePanel("Tim Fruitema Technical Stocks"),


  sidebarLayout(
    sidebarPanel(
      selectInput(stocks, NULL, df.SP500[,1], selected = 1, multiple = FALSE,
                  selectize = FALSE, width = NULL, size = 30),
      actionButton("update", "Submit")

    ),

    # Show a plot of the generated distribution
    mainPanel(
      plotOutput(output$plot)

    )
  )
))

第一個問題似乎是您對getSymbolssrc參數返回錯誤:

Error: ‘getSymbols.google’ is defunct.
Google Finance stopped providing data in March, 2018.
You could try setting src = "yahoo" instead.
See help("Defunct") and help("quantmod-defunct")

你還需要改變input$stock ,以input$stocks (和報價stocks在UI端)。 另外,您需要將output$plot更改output$plot "plot" 我用yahoo代替google

library(shiny)
library(quantmod)
library(BatchGetSymbols)

first.date <- Sys.Date() - 365
last.date  <- Sys.Date()

df.SP500   <- GetSP500Stocks()
tickers    <- df.SP500$tickers

l.out      <- getSymbols(
  tickers    = tickers,
  first.date = first.date,
  last.date  = last.date
)

stocks <- df.SP500[,1]

ui <-fluidPage(

  titlePanel("Tim Fruitema Technical Stocks"),

  sidebarLayout(
    sidebarPanel(
      selectInput("stocks", NULL, df.SP500[,1], selected = 1, multiple = FALSE,
                  selectize = FALSE, width = NULL, size = 30),
      actionButton("update", "Submit")

    ),

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

    )
  )
)


server <- function(input, output) {

  dataInput <- eventReactive(input$update, {
    getSymbols(input$stocks, src = "yahoo",
               auto.assign = FALSE)
  })

  output$plot <- renderPlot({    
    chartSeries(dataInput(), theme = chartTheme("white"))
    addBBands()
    addMACD()
    addRSI()
  })

}

shinyApp(ui, server)

在此處輸入圖片說明

總的來說,您似乎應該再次學習Shiny結構的基礎知識: https : //shiny.rstudio.com/tutorial/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM