It is already hard to find errors in a shiny and the diagnostic messages make it harder. Please see this error:
Warning: Error in FUN: object 'age' not found
182: FUN
181: lapply
180: f
179: l$compute_aesthetics
178: f
177: by_layer
176: ggplot_build.ggplot
174: print.ggplot
166: func
164: f
163: Reduce
154: do
153: hybrid_chain
125: drawPlot
111: <reactive:plotObj>
95: drawReactive
82: origRenderFunc
81: output$totbal
1: runApp
Looking at above chain I am unable to make out anything as to what could be going wrong.
Since my code is quite long I paste the section of the code that is causing this error.
output$totbal <- isolate(renderPlot({
surp_end <- data()[[1]]$surplus_bankbal %>% last() # using data() instead of tdata
if(any(data()[[1]]$surplus_bankbal < 0)) shinyalert("CASH SHORTFALL",text = paste("You will have run out of free cash in year(s):",
paste(which(data()[[1]]$surplus_bankbal < 0),collapse = "," )) )
tdata()[grepl(paste0("total|income|bankbal",input$One_Expense,"|",input$One_Income),variable)] %>%
ggplot(aes(age,value)) +
geom_line(aes(color=variable),size=1) +
geom_point(aes(color = variable),size=3,alpha=0.8) +
geom_label(aes(age,value),data = data.frame(x=max(tdata()$age) - 2,y=200), # for single label reduce the data to a single row data.frame
label= surp_end %>% round(0) %>% format(big.mark=","),
size=12, fill = ifelse(surp_end >0,"green","maroon"), fontface = "bold", color="white",label.size = 1, label.padding = unit(0.7,"lines")) +
geom_text(aes(x=max(tdata()$age) - 2, y=180), label = "Surplus at death",check_overlap = T) +
scale_x_continuous(breaks = 54:95) +
scale_y_continuous(limits = c(0,200),breaks = seq(from=0,to = 200,by=10))
})
Any help (even if educated guesses) would be welcome.
Thanks