Displaying a POSIXt Object Using Shiny renderTable

I am making an application for analyzing time series data using Shiny. The data I'm working with is as follows:

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 build data in a table:

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

By doing this, I get an error when starting Shiny:

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

Does anyone have a solution to this error?

UPDATE: the error is caused by xtable: renderTable uses xtable () to generate output, and it seems that xxtable does not work well with dates in general.

The problem was filed here by Winston Chang: https://github.com/rstudio/shiny/issues/129

A workaround is available at: R: xtable and dates

+6
source share
2 answers

Take a look at the strftime function in the base package. Strftime formats POSIXt objects as a character and allows you to specify the format.

You can do something like this before printing the table:
datasubset$V1 <- strftime(datasubset$V1, format="%Y-%m-%d %H:%M:%S")

+1
source

Hope this helps -

 output$$view <- DT::renderDataTable({ DataFrame<<-read.xlsx(inFile$datapath, 1 ) datatable(DataFrame)%>% formatDate(2, method = 'toISOString') return(DataFrame) }) 

Here you can draw a dataframe "DataFrame" in the mainpanel, and you can also use this dataframe in your application for further calculation / modification with

 return(DataFrame) 
+1
source

All Articles