Filtering dates in Shiny

shiny

#1

Hi, everybody. Cannot resolve a simple task as a poor Shiny guy.

I have a row in a dataframe with dates

crime.date <- strptime(incidents$REPORT_DAT, format = "%Y-%m-%d") 

My output for dates looks like this.

[1] "2017-04-07 EDT" "2017-03-13 EDT" "2017-01-08 EST" "2017-01-25 EST" "2017- 
01-03 EST" "2017-01-03 EST" "2017-01-03 EST"
[8] "2017-01-03 EST" "2017-01-03 EST" "2017-01-03 EST" "2017-01-03 EST" "2017-
01-04 EST" "2017-01-03 EST" "2017-01-03 EST"

Now I try to visualize the selection of all crimes, chosen by this filter.

# USER INTERFACE CODE

ui <- fluidPage(
titlePanel("Washington, DC crimes by date"),

column(4, wellPanel(
dateRangeInput('dateRange',
           label = 'Filter crimes by date',
           start = crime.date , end = crime.date
)
)),
column(6,
 verbatimTextOutput("dateRange")
)
)

# SERVER CODE

server <- function(input, output, session) {
output$dateRangeText  <- renderText({
paste("input$dateRange is", 
  paste(as.character(input$dateRange), collapse = " to ")
 )
})
}

shinyApp(ui = ui, server = server)

I believe that my mistake is somewhere with start and end, because I put there only crime.date variable.

What do I want? I want to select start and end date and receive all incidents, which happened during this period (output as a text is fine for now).

Any help is MUCH APPRECIATED.

Thanks

Oleksiy


#2

try setting start = min(crime.date) and end = max(crime.date)

also a good idea to set min= min(crime.date) and max= max(crime.date) in the dateRangeInput function so that users cannot select a date outwith your data's date range.


#3

Thanks, @paul.
Also got this response from SO.


Will try both options. Much appreciated!