How to calculate the interval between 2 date-time columns in reactive table in R shiny?
library(shiny)
library(rhandsontable)
library(lubridate)
DF = data.frame(baseline = c(as.POSIXct("2019-07-10 14:00:00")), time = c(as.POSIXct("2019-07-10 17:30:00")),interval = c(""), period = c(""))
numberofrows <- nrow(DF)
ui <- basicPage(mainPanel(rHandsontableOutput("hotable1")))
server <- shinyServer(function(input, output, session) {
previous <- reactive({DF})
MyChanges <- reactive({
if(is.null(input$hotable1)){return(previous())}
else if(!identical(previous(),input$hotable1)){
mytable <- as.data.frame(hot_to_r(input$hotable1))
mytable <- mytable[1:numberofrows,]
# test cases
mytable[,1][is.na(mytable[,1])] <- as.POSIXct("2019-07-10 14:00:00")
mytable[,2][is.na(mytable[,2])] <- as.POSIXct("2019-07-10 17:30:00")
mytable[,3] <- as.interval(mytable[,1], mytable[,2], unit="minutes")
mytable[,4] <- as.period(mytable[,3], unit="minute")
mytable
}
})
output$hotable1 <- renderRHandsontable({rhandsontable(MyChanges())})
})
shinyApp(ui, server)
Error: no method or default for coercing “character” to “NA”