I have a datatable (DT) that has a column called days_since_last_event.
days_since_last_event is basically a calculated column of the number of days between the current row timestamp and the previous row timestamp.
i.e. df %>% mutate(days_since_last_event = difftime(as.Date(event_timestamp),lead(as.Date(event_timestamp)),units=c("days")))
The problem is when I apply filters to the DT, days_since_last_event does not recalculate.
Is there an filtering event I can capture or is there someway to recalculate days_since_last_event after the filters are applied?
Here is a code snippet:
observeEvent(input$SearchHost,{
values$hehdata <- load_hh_data(file_name = "Source_query.sql", hw_id = input$inHwID,event_source = "event_source" ,event_timestamp = "event_timestamp", host_status = "host_status",error_indicator = "error_indicator") %>%
mutate(days_since_last_event = difftime(as.Date(event_timestamp),lead(as.Date(event_timestamp)),units=c("days"))) %>% #days since last event
select(hw_id, server_type, dw_etl_date, event_timestamp,days_since_last_event, event_source,biosversion, bmc, host_status, indicator, error_indicator, details)
#output main data table
output$hehdata <- renderDT(values$hehdata,
filter = "top",
escape = FALSE,
options = list(
pageLength = 50, autoWidth = TRUE, columnDefs = list(list(visible=FALSE, targets=c(1,2,3))))
)