繁体   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