Hi can anyone see what is the problem with the code below?
 output$zscore_chart <- renderPlot({
   xvals <- 2:186 
   req(input$countrySelectZScore)
   idx_country = which(input$countrySelectZScore == esiCountries)
   max_comp_z <- max(esiData_DF[idx_country, 2:186], na.rm = TRUE)
   overall_max_z <- max(max_comp_z, na.rm = TRUE)
   foo = ts(esiData_DF[idx_country, 2:186], frequency = 12, start = 2001)
   dates = seq(as.Date("2001-01-01"), by = "month", along = foo)
   plot(x = 2:186, y = esiData_DF[idx_country, 2:186], type = "l", 
        xlab = "", ylab = "", col = "grey20", ylim = c(-2, overall_max_z),
        lwd=3,las=2)
    mtext("Quarterly percentage changes", side = 3, adj = 0, line = 0.1, 
      cex = 1, font = 0.5)
    axis(1, at = xvals, label = dates, cex.axis = 1, las = 2)
    mtext("Economic Sentiment Indicators", side = 3, adj = 0, 
          line = 1.2, cex = 2, font = 2)
    legend(
      "bottom", 
      lty = c(1,1), 
      lwd = c(3,3), 
      col = c("grey20", "green2"), 
      legend = c("Economic Sentiment Indicator", "GDP growth"),
      bty = "n",
      xjust = 0.5,
      yjust = 0.5,
      horiz = TRUE
    )
  }, height = 525)
esiData_DF is the DF used to index and plot the correct data. The dataframe has the country names down the left hand side with the dates, monthly across the top. I need the plot to render but it wont when I run the app. Any ideas?
The data continues to the right, up to May 2017 monthly.

 
    