I am having a bit of trouble with a basic thing I am trying to create in Shiny. I want the user to select which variables will be plotted and based on that entry the appropriate subset of the data will be made and plotted.
shinyServer(function(input, output) {
output$value <- renderPrint({ input$checkGroup })
output$vehPlot <- renderPlot({
output$vehPlot <- reactivePlot(function() {
if (input$variable == "pur") {
# am
if(!is.na(input$checkGroup[1]==1 & input$checkGroup[2]==2 & input$checkGroup[3]==3)) { #all check boxes
vehData <- data.frame(newp[ which(newp$type=='2WD' | newp$type=='4WD'| newp$type=='ATV'), ])
}
else if(!is.na(input$checkGroup[1]==1)) { #only check box one
vehData <- data.frame(newp[ which(newp$type=='2WD'), ])
}
else if(!is.na(input$checkGroup[1]==2)) { #only check box two
vehData <- data.frame(newp[ which(newp$type=='4WD'), ])
}
else if(!is.na(input$checkGroup[1]==3)) { #only check box three
vehData <- data.frame(newp[ which(newp$type=='ATV'), ])
}
else{
vehData <- data.frame(Date=as.Date(character()),
File=character(),
User=character(),
stringsAsFactors=FALSE)
}
}
else {
# cyl and gear
vehData <- data.frame(new)
}
p <- ggplot(data=vehData,aes(x=vehData$year,y=vehData$num, group=vehData$type,colour=vehData$type)) +
geom_line()+
geom_point()
print(p)
})
}) })
So as it stands, only 2WD variable can be plotted on its own. Whenever I select 4WD on its own for example, the correct subset is not being made and all three are plotted.
I don't believe it is an issue with the reactive functions but I could be wrong or maybe not accessing the checkGroup output correctly. Also being newish to Shiny doesn't help.
Cheers.