[英]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)
)
)
))
第一個問題似乎是您對getSymbols
的src
參數返回錯誤:
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.