Recalculating difftime in datatable after filtering

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:


    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))))

Hi @clemlau,

I don't think I can provide a definitive answer, but I think what's happening is that you do the difftime on the server side, while the DT filtering is done on the client side (in the web browser). There is posibiity to do server-side processing in the DT library, you can have a look here:

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.