Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing time and dateformat to show correct format on shiny dashboard

I've build this dashboard with multiple date and time columns however in the dashboard the "T" and "Z" popup in the display LIKETHIS Any ideas on how to remove this? I tried as.character, as.factor, anytime but I'm not able to make it happen.

Any other ideas are appreciated!

like image 635
kishore Avatar asked Nov 01 '25 01:11

kishore


2 Answers

This happens when you go from R to Javascript. You need to add:

 output$yourDT <- DT::renderDataTable({
     DT::datatable(df) %>% formatDate(3, "toLocaleString")
 })

Where the 3 represents the position of the date (as.POSIXct(), not factor, for example) column (e.g., third column) you are formatting.

like image 168
calycolor Avatar answered Nov 03 '25 17:11

calycolor


You can parse it in base R or with lubridate :

tz <- Sys.timezone()

date1 <- "2015-03-23T13:23:20Z"

# With {base}
strptime(date1, tz = tz, format = "%Y-%m-%dT%H:%M:%OSZ")
[1] "2015-03-23 13:23:20 CET"


#With lubridate
lubridate::ymd_hms(date1, tz = tz)
[1] "2015-03-23 14:23:20 CET"

You can of course specify a different timezone for tz.

Best,

Colin

like image 30
Colin FAY Avatar answered Nov 03 '25 18:11

Colin FAY



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!