I'm creating a reporting tool for an online market. I want to add a checkbox, "Coupon", where only observations that have a positive value in the Coupon field are selected.
So, in ui.R I have:
checkboxInput("checkbox", label = "Coupon", value = TRUE)
This is working fine.
In server.R I have:
Coupon_Select <- reactive({
if(input$checkbox == TRUE){0}
else {-1}
})
and
Data_Select <- reactive({
Orders %>%
filter(Region %in% Region_Select(), Community.Type %in% Type_Select(),
Coupon > Coupon_Select()
)
})
The idea here is that if the Checkbox is checked, dplyr would only select observations whose 'Coupon' value > 0. If it's not checked, it would select observations whose 'Coupon' value > -1. However, I realize now it doesn't work because Coupons with no value are given a NA - therefore, regardless of the value of the checkbox, I'm only getting observations with coupon values > 0.
So, my question is, how can I make dplyr output only observations with Coupon values that aren't NA when the checkbox is checked, and all observations when it's not checked?