1

My POSIXct timestamps contain microsecond precision which I need to visualise. Is there any concise way to do this with DT, or is my only option to transform the POSIXct to a string on R side?

Here is a tryout minimal example:

library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(DTOutput('tbl')),
  server = function(input, output) {
    output$tbl = renderDataTable({
        dt <- data.table::data.table(ts = as.POSIXct(1.654321, origin = '1970-01-01'))
        dt[, ts.DT_formatDate := ts]
        dt[, ts.converted_in_r_to_string := format(ts, format = '%Y-%m-%dT%H:%M:%OS6Z', tz = 'UTC')]

        DT <- datatable(data = dt)

        DT <- formatDate(
          DT, columns = 'ts.DT_formatDate', method = 'toISOString',
          params =  list('en-US', list(year = 'numeric', month = 'long', day = 'numeric', fractionalSecondDigits = 3))
        )

        DT
    })
  }
)

enter image description here

I don't think Moment.js is implemented in DT. It allows many date/time transformation options on the client side and could be a solution.

Davor Josipovic
  • 5,296
  • 1
  • 39
  • 57

0 Answers0