Retrieving stored ARIMA model using REACTIVE function -- Error in as.vector: cannot coerce type 'closure' to vector of type 'character



I have saved a ARIMA model and Validation dataframe containing (sales & price) as RDS objects and trying to retrieve the same using REACTIVE functions.

server <- function(input,output) {              

  m_arima_model <- reactive({

  m_valid_data <- reactive({

  output$FC <- renderPlot({
     m_fc <- forecast(m_arima_model(), 
                        xreg = 

But this is throwing the following error Error in as.vector: cannot coerce type 'closure' to vector of type 'character'. I have also tried moving m_arima_model() to another variable inside renderPlot which throws the same error. Can you please help ?

I am not sure whether accessing the validation price using m_valid_data()$price[1:input$horizon] is right as well. The horizon value is from input variables.


Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

Error in as.vector: cannot coerce type 'closure' to vector of type 'character

I feel the error message is pretty clear, somewhere a function (closure) is being applied where a vector of type character is expected. I'm pretty sure the lines where you define m_arima_model and m_valid_data are just setting them us as functions, so when you apply them to forecast you get this error.


m_arima_model <- reactive({
#> [1] "closure"

Created on 2018-08-01 by the reprex package (v0.2.0.9000).


I am sorry. This was my mistake. I missed out on using an earlier reactive call. Thank you @EconomiCurtis for suggesting to create a REPPEX, which is when I was able to isolate the issue in my code. Thank you all.


If your question's been answered (even by you! especially by you solving it yourself in the course of making a reprex :heart_eyes:), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: