Issue:
I'm experiencing a weird issue with dplyr's filter verb. I am trying to filter a data.frame by the current month and current year. I have created a reactive function for both:
current.month <- reactive({
gsub("0", " ", format(Sys.Date(), "%m"))
current.year <- reactive({
format(Sys.Date(), "%Y")
When I try to filter by the reactive expression, my data.frame does not return any results. This is despite the fact that the date column in my data.frame is of type character as is the current.month()
& current.year()
reactive values.
What I have:
df[df$REPORT == input$dropdown.report, ] %>%
filter(Month == current.month() & Year == current.year())
This does not return any output.
However, when I hard-code the inputs, my table returns without any problems.
df[df$REPORT == input$dropdown.report, ] %>%
filter(Month == "4" & Year == "2018")
Can anyone steer me in the right direction? You can recreate this exact issue with the iris dataset. I understand output is important for a reproducible example, but I cannot share my company's data.
Edit:
For counting purposes, my data.frame has date variables separated into 2 columns: Month, Year. Month is a single character with no leading 0 - which is why I need to use the gsub function above.