Commit 653dfeba authored by dmattek's avatar dmattek

Changed: check for empty dt replaced by explicit zeroRecords option to DT.

parent 3ee73121
...@@ -38,8 +38,8 @@ modTrackStats = function(input, output, session, ...@@ -38,8 +38,8 @@ modTrackStats = function(input, output, session,
DT::dataTableOutput(ns('outTabStatsMeas'))), DT::dataTableOutput(ns('outTabStatsMeas'))),
tabPanel("Duplicated IDs", tabPanel("Duplicated IDs",
DT::dataTableOutput(ns('outTabStatsDup'))) DT::dataTableOutput(ns('outTabStatsDup')))
)
) )
)
} }
}) })
...@@ -60,7 +60,7 @@ modTrackStats = function(input, output, session, ...@@ -60,7 +60,7 @@ modTrackStats = function(input, output, session,
}) })
# caclulate stats of the measurement (column Y) per group # calculate stats of the measurement (column Y) per group
calcStatsMeas = reactive({ calcStatsMeas = reactive({
cat(file = stderr(), 'modTrackStats:calsStats\n') cat(file = stderr(), 'modTrackStats:calsStats\n')
loc.dt = in.data() loc.dt = in.data()
...@@ -83,7 +83,7 @@ modTrackStats = function(input, output, session, ...@@ -83,7 +83,7 @@ modTrackStats = function(input, output, session,
return(loc.dt.aggr) return(loc.dt.aggr)
}) })
# caclulate stats of tracks per group # calculate stats of tracks per group
calcStatsTracks = reactive({ calcStatsTracks = reactive({
cat(file = stderr(), 'modTrackStats:calsStats\n') cat(file = stderr(), 'modTrackStats:calsStats\n')
loc.dt = in.data() loc.dt = in.data()
...@@ -94,10 +94,10 @@ modTrackStats = function(input, output, session, ...@@ -94,10 +94,10 @@ modTrackStats = function(input, output, session,
loc.dt.aggr = loc.dt[, loc.dt.aggr = loc.dt[,
.(nTpts = .N), .(nTpts = .N),
by = c(in.bycols, COLID)][, .(tracksN = .N, by = c(in.bycols, COLID)][, .(tracksN = .N,
tracksLenMean = mean(nTpts), tracksLenMean = mean(nTpts),
tracksLenSD = sd(nTpts), tracksLenSD = sd(nTpts),
tracksLenMedian = median(as.double(nTpts)), tracksLenMedian = median(as.double(nTpts)),
tracksLenIQR = IQR(nTpts)), by = c(in.bycols)] tracksLenIQR = IQR(nTpts)), by = c(in.bycols)]
setnames(loc.dt.aggr, c(in.bycols, 'nTracks', 'Mean Length', 'SD', 'Median Length', 'IQR')) setnames(loc.dt.aggr, c(in.bycols, 'nTracks', 'Mean Length', 'SD', 'Median Length', 'IQR'))
...@@ -109,8 +109,9 @@ modTrackStats = function(input, output, session, ...@@ -109,8 +109,9 @@ modTrackStats = function(input, output, session,
cat(file = stderr(), 'modTrackStats:outTabStats\n') cat(file = stderr(), 'modTrackStats:outTabStats\n')
loc.dt = calcStatsTracks() loc.dt = calcStatsTracks()
if (is.null(loc.dt)) validate(
return(NULL) need(!is.null(loc.dt), "Cannot calculate statistics. Load data first!")
)
if (nrow(loc.dt)) if (nrow(loc.dt))
datatable(loc.dt, datatable(loc.dt,
...@@ -141,8 +142,9 @@ modTrackStats = function(input, output, session, ...@@ -141,8 +142,9 @@ modTrackStats = function(input, output, session,
cat(file = stderr(), 'modTrackStats:outTabMeas\n') cat(file = stderr(), 'modTrackStats:outTabMeas\n')
loc.dt = calcStatsMeas() loc.dt = calcStatsMeas()
if (is.null(loc.dt)) validate(
return(NULL) need(!is.null(loc.dt), "Cannot calculate statistics. Load data first!")
)
if (nrow(loc.dt)) if (nrow(loc.dt))
datatable(loc.dt, datatable(loc.dt,
...@@ -174,35 +176,39 @@ modTrackStats = function(input, output, session, ...@@ -174,35 +176,39 @@ modTrackStats = function(input, output, session,
cat(file = stderr(), 'modTrackStats:outTabStatsDup\n') cat(file = stderr(), 'modTrackStats:outTabStatsDup\n')
loc.dt = in.data() loc.dt = in.data()
if (is.null(loc.dt)) validate(
return(NULL) need(!is.null(loc.dt), "Cannot calculate statistics. Load data first!")
)
# Look whether there were more objects with the same track ID in the frame # Look whether there were more objects with the same track ID in the frame
# Such track IDs will have TRUE assigned in 'dup' column # Such track IDs will have TRUE assigned in 'dup' column
# Keep only s.track column with dup=TRUE # Keep only s.track column with dup=TRUE
loc.duptracks = loc.dt[, .(dup = (sum(duplicated(get(COLRT))) > 0)), by = COLID][dup == TRUE, COLID, with = FALSE] loc.duptracks = loc.dt[,
.(dup = (sum(duplicated(get(COLRT))) > 0)),
if (nrow(loc.duptracks)) by = COLID][dup == TRUE, COLID, with = FALSE]
datatable(loc.duptracks,
caption = paste0("Track IDs with duplicated objects in a group. ", DT::datatable(loc.duptracks,
"To avoid, create a data-wide unique track ID in ", caption = paste0("Time series with duplicated track IDs. ",
"the panel on the left or in your input data."), "To avoid, create a data-wide unique track ID in ",
rownames = TRUE, "the panel on the left or in your input data."),
extensions = 'Buttons', rownames = TRUE,
options = list( extensions = 'Buttons',
dom = 'Bfrtip', options = list(
buttons = list('copy', dom = 'Bfrtip',
'print', buttons = list('copy',
list(extend = 'collection', 'print',
buttons = list(list(extend='csv', list(extend = 'collection',
filename = 'hitStats'), buttons = list(list(extend='csv',
list(extend='excel', filename = 'hitStats'),
filename = 'hitStats'), list(extend='excel',
list(extend='pdf', filename = 'hitStats'),
filename= 'hitStats')), list(extend='pdf',
text = 'Download')))) %>% formatRound(3:6) filename= 'hitStats')),
else text = 'Download')),
return(NULL) language = list(
zeroRecords = "No records to display")
)
) %>% formatRound(3:6)
}) })
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment