diff --git a/server.R b/server.R index f264f54eaa9b229709dd0f263d88783a0d6a157f..1123c0f147f26cf35fe2b9f8c574ee01cfd3b94a 100644 --- a/server.R +++ b/server.R @@ -144,14 +144,16 @@ shinyServer(function(input, output, session) { output$varSelTimeFreq = renderUI({ cat(file = stderr(), 'UI varSelTimeFreq\n') - numericInput( - 'inSelTimeFreq', - 'Provide time frequency:', - min = 1, - step = 1, - width = '100%', - value = 1 - ) + if (input$chBtrajInter) { + numericInput( + 'inSelTimeFreq', + 'Provide time frequency:', + min = 1, + step = 1, + width = '100%', + value = 1 + ) + } }) # This is main field to select plot facet grouping @@ -619,34 +621,37 @@ shinyServer(function(input, output, session) { # Therefore, we cnanot rely on that info to get time frequency; user provides this number! setkey(loc.out, group, id, realtime) - - # here we fill missing data with NA's - loc.out = loc.out[setkey(loc.out[, .(seq(min(realtime), max(realtime), input$inSelTimeFreq)), by = .(group, id)], group, id, V1)] - # x-check: print all rows with NA's - print('Rows with NAs:') - print(loc.out[rowSums(is.na(loc.out)) > 0, ]) - - # NA's may be already present in the dataset'. - # Interpolate (linear) them with na.interpolate as well - if(locPos) - s.cols = c('y', 'pos.x', 'pos.y') - else - s.cols = c('y') - - loc.out[, (s.cols) := lapply(.SD, na.interpolation), by = id, .SDcols = s.cols] - - - # !!! Current issue with interpolation: - # The column mid.in is not taken into account. - # If a trajectory is selected in the UI, - # the mid.in column is added (if it doesn't already exist in the dataset), - # and for the interpolated point, it will still be NA. Not really an issue. - # - # Also, think about the current option of having mid.in column in the uploaded dataset. - # Keep it? Expand it? - # Create a UI filed for selecting the column with mid.in data. - # What to do with that column during interpolation (see above) + if (input$chBtrajInter) { + # here we fill missing data with NA's + loc.out = loc.out[setkey(loc.out[, .(seq(min(realtime), max(realtime), input$inSelTimeFreq)), by = .(group, id)], group, id, V1)] + + # x-check: print all rows with NA's + print('Rows with NAs:') + print(loc.out[rowSums(is.na(loc.out)) > 0, ]) + + # NA's may be already present in the dataset'. + # Interpolate (linear) them with na.interpolate as well + if(locPos) + s.cols = c('y', 'pos.x', 'pos.y') + else + s.cols = c('y') + + loc.out[, (s.cols) := lapply(.SD, na.interpolation), by = id, .SDcols = s.cols] + + + # !!! Current issue with interpolation: + # The column mid.in is not taken into account. + # If a trajectory is selected in the UI, + # the mid.in column is added (if it doesn't already exist in the dataset), + # and for the interpolated point, it will still be NA. Not really an issue. + # + # Also, think about the current option of having mid.in column in the uploaded dataset. + # Keep it? Expand it? + # Create a UI filed for selecting the column with mid.in data. + # What to do with that column during interpolation (see above) + + } ## Trim x-axis (time) if(input$chBtimeTrim) { diff --git a/ui.R b/ui.R index 783d5bb6128e7b8bb6c4714a1dfd3e4437d960c9..801274fb5d42fd4f2882244f7bfd931a7a92bf84 100644 --- a/ui.R +++ b/ui.R @@ -42,6 +42,7 @@ shinyUI(fluidPage( uiOutput('uiButLoadTrajRem'), tags$hr(), + checkboxInput('chBtrajInter', 'Interpolate NAs?', value = T), checkboxInput('chBtrackUni', 'Create unique TrackLabel', T), helpPopup( title = 'Create unique cell ID',