I am new to R and RShiny and I feel a little lost right now. I am trying to do a simple financial forecast based on the small moving medium average in R Shiny. I tried it in R Studio and it worked, but I can not get the code to work in my app. I receive the error message "unused argument (.)"
- This is how I get the data into R Shiny
# acquiring data
dataInput <- reactive({ ##reactive expressions make code faster, they can be called anywhere in the app
req(input$symb)
req(input$dates)
return(isolate({ ## with isolate reactive expression can be read, but cannot cause the reactive scope of the caller to be re-evaluated when they change
getSymbols(input$symb, src="yahoo", ##here we get the input data from yahoo
from = input$dates[1],
to = input$dates[2],
warnings = FALSE,
auto.assign = FALSE)
}))
})
- This is how I try to plot the data in the UI
mainPanel(tabsetPanel(id = "tab", ##creates different tabs, id can be referenced in Server logic
tabPanel("Forecast", icon = icon("rectangle-list"), plotOutput(outputId = "forecast", height = "400px"))
- This is what in do in the server function
output$forecast<- renderPlot({
req(input$dates)
df <- data.frame(dataInput()) #convert into data frame
names(df) <-c("Open", "High", "Low", "Close", "Volume", "Adjusted")
df$Date <- as.Date(rownames(df))
df$MA10 <- TTR::SMA (df$Close, n = 100)
ts<- df$MA10%>%dataInput()
fma <-forecast(ts, h=100)
fma
})## End renderPlot
2.This is what I did in R Studio and it worked
#required libraries
install.packages("install.load")
require ("install.load")
install_load(c("ggplot2", "TTR",
"quantmod", "forecast", "TSstudio", "pracma", "dplyr"))
#define variables so that you can change the ticker symbol
Share <- "FSLR"
StartDate <- "2000-01-01"
EndDate <- "2022-01-15"
#get data in df
#load stock prices into object called df, hence auto.assign = FALSE
# if auto.assign = TRUE the data gets loaded to an object which is the same as the name(symbol) of the stock
ts <- getSymbols(Share
, from = StartDate
, to = EndDate
, warnings = FALSE
, auto.assign = FALSE)
df <- data.frame(ts) #convert into data frame
names(df) <-c("Open", "High", "Low", "Close", "Volume", "Adjusted")
df$Date <- as.Date(rownames(df))
df$MA10 <- TTR::SMA (df$Close, n = 100)
ts <- df$MA10%>%ts
fma <-forecast (ts, h=100)
fma
plot(fma, xlab ="Days", ylab = "Closing prices", main = "100 days forecast based on moving average")
- I think the problem lies here, but I am not sure on how to solve it
ts<- df$MA10%>%dataInput()