I've a problem with my shiny code which is somewhat related with the two questions I linked below.
So i've made a dynamic UI :
output$hmgroupsmean <-renderUI({
numGroups <- as.integer(input$HMgroups)
lapply(1:numGroups, function(i) {
numericInput(paste0("group_", i),
label= paste("Mean", i),
min=0,
max=1000,
value= 10)
})
})
that display N numericInput depending on how many groups the user has chosen. Then I just want to retrieve all the mean and there begin the problem : I tried what is explained here but it doesnt work :
output$PowerAnalysisANOVA <- renderPlot({
allmean = c()
lapply(1:numGroups, function(i){
allmean[i] <- input[[paste0("group_", i)]]
})
qplot(allname)
})
it returns : Error : argument "env" is missing, with no default
then i tried something a tad more exotic :
output$PowerAnalysisANOVA <- renderPlot({
allname = c()
allmean = c()
lapply(1:numGroups, function(i){
allname[i] <- paste0("input$group_" ,i)
allmean[i] <- get(allname[i])
})
qplot(allmean)
})
But it doesn't work : Error :object 'input$group_1' not found
Edit after AndriyTkach's comment :
output$PowerAnalysisANOVA <- renderPlot({
allname = c()
allmean = c()
lapply(1:numGroups, function(i){
allname[i] <- eval(parse (text = paste0("input$group_" ,i)))
allmean[i] <- get(allname[i])
})
qplot(allmean)
})
It returns a new Error : invalid first argument
AndriyTkach proposed that :
for (i in 1:numGroups)
eval (parse (text = paste0("allmean[", i, "] <- input$group_" ,i)))
Which work a lot better : no Error message but it only work for 2 and 3 groups , the fourth and up is not taken into account Create dynamic number of input elements with R/Shiny accessing inputs created in renderUI in Shiny