I have a population and area-type columns in the data table where I want the user to do conditional filtering (say select population>15000 & area-type is planned). I am using a reactive function, the areatype is working while the population isn't reactive. I am thinking of using the observe function but I don't know. My question is how to make both reactive & include dependency. Code:
#UI
ui<-fluidpage(checkboxGroupInput(inputId = "popdensity",
label = " Population Per Km2:",
choices = list(
"< 15,000"=1,
"15,001 - 30,000"=2 ,
">30,000"=3
),
selected =list(1,2,3)
),
selectInput(inputId = "area",
label = " AreaType:",
choices = c(
"All",
unique(as.character(nakuru$AreaType))
)
))
#SERVER
server<-function(input,output)({
output$table<-DT::renderDataTable({
#filtering based on user selection
dt<-reactive({
df<-nakuru
if(input$area!="All"){
df<-df[df$AreaType==input$area,]
}
if(input$popdensity==1){
df[df$PopDensity<=15000,]
}
if(input$popdensity==2){
df[df$PopDensity>15000&df$PopDensity<=30000,]
}
if(input$popdensity==3){
df[df$PopDensity>30000,]
}
df
})
DT::datatable(dt(),options = list(scrollX=TRUE))
})
})