如何让这个R脚本工作
我很难理解为什么输入不能传递到服务器端,在绘图中处理和返回。我真的希望有人能在UI/服务器动态的工作原理上给我启发如何让这个R脚本工作,r,shiny,R,Shiny,我很难理解为什么输入不能传递到服务器端,在绘图中处理和返回。我真的希望有人能在UI/服务器动态的工作原理上给我启发 library(shiny) library(quantmod) library(BatchGetSymbols) # Define server logic required to draw a histogram shinyServer(function(input, output) { dataInput <-
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,并在UI端对stocks进行报价。此外,还需要将输出$plot更改为just plot。我用雅虎而不是谷歌:
总的来说,您似乎应该再次学习闪亮结构的基础知识:您需要进一步解释您在调试方面所做的尝试。你也看了一些类似的问题吗?谢谢!!它确实一直在工作,感觉像是一个小错误,但我认为你是正确的,我是一个有光泽的初学者,将接受你的建议,再次通过必要的材料!
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)