6

I'm making an app to analyse time series data with Shiny. The data I work with looks like:

                   V1     V2
1 2013-02-04 18:15:00 -4.746
2 2013-02-04 18:20:00 -4.745
3 2013-02-04 18:25:00 -4.746
4 2013-02-04 18:30:00 -4.747
5 2013-02-04 18:35:00 -4.747
6 2013-02-04 18:40:00 -4.747

I want to plot the data in a table:

output$view <- renderTable({
  head(datasubset(), 
  n=nrow(datasubset()))
})

Doing so I get an error when running Shiny:

Error in Math.POSIXt(x + ifelse(x == 0, 1, 0)) : 
      'abs' not defined for "POSIXt" objects

Does anyone have a solution for this error?

UPDATE: The error is caused by xtable: renderTable uses xtable() to generate the output, and it looks like xtable doesn't play well with dates in general.

An issue has been filed here by Winston Chang: https://github.com/rstudio/shiny/issues/129

A workaround is available at: R: xtable and dates

Community
  • 1
  • 1
Timror
  • 800
  • 7
  • 17

2 Answers2

3

Look into the strftime function in base package. Strftime formats POSIXt objects as character, and lets you specify the format.

You could do someting like this before you print the table:
datasubset$V1 <- strftime(datasubset$V1, format="%Y-%m-%d %H:%M:%S")

snaut
  • 2,261
  • 18
  • 37
1

Hope this will help-

output$$view  <- DT::renderDataTable({

DataFrame<<-read.xlsx(inFile$datapath, 1 )

datatable(DataFrame)%>%
  formatDate(2, method = 'toISOString')

return(DataFrame)

 })

Here you can plot the dataframe "DataFrame" in mainpanel and also can use this dataframe in your application for further calculation/modification by using

return(DataFrame)
mehakVT
  • 167
  • 1
  • 8