maRtin
maRtin

Reputation: 6516

R: Shiny dateRangeInput format

I am using the packet shiny for R and I implemented a dateRangeInput in my ui.R:

   dateRangeInput("date", "Date range:",
                       start  = "2013-05-15",
                       end    = "2013-10-01",
                       min    = "2013-05-15",
                       max    = "2013-10-01",
                       format = "dd/mm/yy",
                       separator = " - ")

If I display the selected min and max values, i get the following (weird) output:

Min date value:

renderText({(input$date[1])})

Output:

 15840

Max date value:

renderText({(input$date[2])})

Output:

15979

Why do I get these numbers in the output and not the selected ate from the ui.R itself: 2013-05-15 and 2013-10-01 ? And how can I transform it to such a format? as.Date does not work.

Upvotes: 13

Views: 16851

Answers (3)

Andrii
Andrii

Reputation: 3043

In my case for dateRangeInput selector, the results were strings

date_start <- input$dateRangeInput_name_one[1]
date_end <- input$dateRangeInput_name_one[2]

BTW: If you 'date' is integer you can convert it to 'date' by using the following code:

 date_start_date <- as.Date(date_start, origin = "1970-01-01")
 date_end_date <- as.Date(date_end, origin = "1970-01-01")

Upvotes: 3

mdsumner
mdsumner

Reputation: 29525

The actual value is days since the unix epoch, use format(input$date[1]).

Upvotes: 16

Indraneel
Indraneel

Reputation: 316

You can use some thing like this

observe({
x <- format(input$date[1])

  cat(x,file="/home/indraneel/temp/r1outfile.txt",append=TRUE)

})

Upvotes: 3

Related Questions