I'm trying to create a shiny based on a R code previously created.
The problem I'm facing is that the for loops are not working.
One example would be:
centros.acp=reactive({colMeans(a.acp())})
lcov.acp=reactive({solve(cov(a.acp()))})
dm.acp=reactive({rep(0,length(a.acp()[,1]))})
na.acp=reactive({a.acp()[1]})
dm.acp()=reactive({
value=dm.acp()
for(i in na.acp()){
value()[i]<-reactive({round(t(a.acp()[i,]-centros.acp())%*%lcov.acp()%*%(a.acp()[i,]-centros.acp()),3)
})}})
T2<-reactive({dm.acp()})
my_list=reactive({list("T2" = T2(),"cc.sw.UCL.99" = cc.sw.UCL.99(),"cc.sw.UCL.95" = cc.sw.UCL.95(), "num.com"=num.com())})
output$plot_t2=renderPlot({plot(1:n(),my_list()$T2, ylim = c(0,max(my_list()$T2,my_list()$cc.sw.UCL.99)+3),main = "",
xlab = 'OBS',ylab = 'T2') })
I get the error
Error in dm.acp() = reactive({ : invalid (NULL) left side of assignment
The code I show is the only part that matters for the problem, everything else is working. I have tried different ways but always get the error or the graph plotted is based on the original dm.acp() that consists in group of 0. When I run the for loop, I want to substitute the 0 by values (in each iteration a new number is changed).
The original dm.acp() is
> dm.acp
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[50] 0 0 0 0 0 0 0 0 0 0 0
and after the for loop should be
[1] 6.210 3.663 4.246 4.279 3.766 3.583 2.957 4.796 4.578 3.225 4.232 2.865 6.976 3.454
[15] 3.411 3.530 3.610 22.747 9.936 2.659 3.080 6.412 9.183 2.781 3.253 5.585 3.183 5.171
[29] 3.898 5.868 2.498 12.901 2.772 2.795 1.644 1.393 21.078 2.489 3.198 2.412 4.213 4.251
[43] 8.144 3.201 3.295 4.378 4.746 9.481 4.281 4.402 5.329 2.637 2.627 4.507 5.521 3.545
[57] 2.623 5.835 2.438 3.230
I appreciate any help. Thank you !