Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pertz-lab
shiny-timecourse-inspector
Commits
b2263127
Commit
b2263127
authored
Oct 10, 2019
by
dmattek
Browse files
Moved interpolation to an external function
parent
ffba53a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
server.R
View file @
b2263127
...
@@ -182,6 +182,8 @@ shinyServer(function(input, output, session) {
...
@@ -182,6 +182,8 @@ shinyServer(function(input, output, session) {
# UI-side-panel-column-selection ----
# UI-side-panel-column-selection ----
# Select a column with time series ID
output
$
varSelTrackLabel
=
renderUI
({
output
$
varSelTrackLabel
=
renderUI
({
if
(
DEB
)
if
(
DEB
)
cat
(
file
=
stdout
(),
'server:varSelTrackLabel\n'
)
cat
(
file
=
stdout
(),
'server:varSelTrackLabel\n'
)
...
@@ -198,6 +200,7 @@ shinyServer(function(input, output, session) {
...
@@ -198,6 +200,7 @@ shinyServer(function(input, output, session) {
)
)
})
})
# Select a column with time
output
$
varSelTime
=
renderUI
({
output
$
varSelTime
=
renderUI
({
if
(
DEB
)
if
(
DEB
)
cat
(
file
=
stdout
(),
'server:varSelTime\n'
)
cat
(
file
=
stdout
(),
'server:varSelTime\n'
)
...
@@ -214,22 +217,6 @@ shinyServer(function(input, output, session) {
...
@@ -214,22 +217,6 @@ shinyServer(function(input, output, session) {
)
)
})
})
output
$
varSelTimeFreq
=
renderUI
({
if
(
DEB
)
cat
(
file
=
stdout
(),
'server:varSelTimeFreq\n'
)
if
(
input
$
chBtrajInter
)
{
numericInput
(
'inSelTimeFreq'
,
'Interval between 2 time points'
,
min
=
1
,
step
=
1
,
width
=
'100%'
,
value
=
1
)
}
})
# This is the main field to select plot facet grouping
# This is the main field to select plot facet grouping
# It's typically a column with the entire experimental description,
# It's typically a column with the entire experimental description,
# e.g.1 Stim_All_Ch or Stim_All_S.
# e.g.1 Stim_All_Ch or Stim_All_S.
...
@@ -279,7 +266,7 @@ shinyServer(function(input, output, session) {
...
@@ -279,7 +266,7 @@ shinyServer(function(input, output, session) {
}
}
})
})
# Select a column with the measurement
output
$
varSelMeas1
=
renderUI
({
output
$
varSelMeas1
=
renderUI
({
if
(
DEB
)
if
(
DEB
)
cat
(
file
=
stdout
(),
'server:varSelMeas1\n'
)
cat
(
file
=
stdout
(),
'server:varSelMeas1\n'
)
...
@@ -298,7 +285,8 @@ shinyServer(function(input, output, session) {
...
@@ -298,7 +285,8 @@ shinyServer(function(input, output, session) {
}
}
})
})
# Select a column with the 2nd measurement.
# Some simple operations can be performed betwee the two meaurements
output
$
varSelMeas2
=
renderUI
({
output
$
varSelMeas2
=
renderUI
({
if
(
DEB
)
if
(
DEB
)
cat
(
file
=
stdout
(),
'server:varSelMeas2\n'
)
cat
(
file
=
stdout
(),
'server:varSelMeas2\n'
)
...
@@ -352,6 +340,24 @@ shinyServer(function(input, output, session) {
...
@@ -352,6 +340,24 @@ shinyServer(function(input, output, session) {
return
(
input
$
slTimeTrim
)
return
(
input
$
slTimeTrim
)
})
%>%
debounce
(
MILLIS
)
})
%>%
debounce
(
MILLIS
)
# UI-side-panel-interpolation ----
# Provide interval between 2 time points (for interpolation of NAs and missing time points)
output
$
varSelTimeFreq
=
renderUI
({
if
(
DEB
)
cat
(
file
=
stdout
(),
'server:varSelTimeFreq\n'
)
if
(
input
$
chBtrajInter
)
{
numericInput
(
'inSelTimeFreq'
,
'Interval between 2 time points'
,
min
=
0
,
step
=
1
,
width
=
'100%'
,
value
=
1
)
}
})
# UI-side-panel-normalization ----
# UI-side-panel-normalization ----
# select normalisation method
# select normalisation method
...
@@ -740,55 +746,46 @@ shinyServer(function(input, output, session) {
...
@@ -740,55 +746,46 @@ shinyServer(function(input, output, session) {
else
else
closeAlert
(
session
,
"alertNAsPresent"
)
closeAlert
(
session
,
"alertNAsPresent"
)
setkeyv
(
loc.out
,
c
(
COLGR
,
COLID
,
COLRT
))
# check if time between 2 time points provided
if
(
input
$
chBtrajInter
)
{
if
(
input
$
chBtrajInter
)
{
if
(
input
$
inSelTimeFreq
==
0
)
# here we fill missing rows with NA's
createAlert
(
session
=
session
,
loc.out
=
loc.out
[
setkeyv
(
loc.out
[,
anchorId
=
"alertAnchorSidePanelNAsPresent"
,
.
(
seq
(
min
(
get
(
COLRT
),
na.rm
=
T
),
alertId
=
"alertTimeFreq0"
,
max
(
get
(
COLRT
),
na.rm
=
T
),
title
=
"Error"
,
input
$
inSelTimeFreq
)),
content
=
helpText.server
[[
"alertTimeFreq0"
]],
by
=
c
(
COLGR
,
COLID
)],
c
(
COLGR
,
COLID
,
'V1'
))]
append
=
FALSE
,
style
=
"danger"
)
# x-check: print all rows with NA's
if
(
DEB
)
{
cat
(
file
=
stdout
(),
'server:dataLong: Rows with NAs:\n'
)
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
(
COLY
,
COLPOSX
,
COLPOSY
)
else
else
s.cols
=
c
(
COLY
)
closeAlert
(
session
,
"alertTimeFreq0"
)
}
# Interpolated columns should be of type numeric (float)
# This is to ensure that interpolated columns are of porper type.
# required for subsetting downstream
setkeyv
(
loc.out
,
c
(
COLGR
,
COLID
,
COLRT
))
# Apparently the loop is faster than lapply+SDcols
for
(
col
in
s.cols
)
{
#loc.out[, (col) := as.numeric(get(col))]
data.table
::
set
(
loc.out
,
j
=
col
,
value
=
as.numeric
(
loc.out
[[
col
]]))
loc.out
[,
(
col
)
:=
na_interpolation
(
get
(
col
)),
by
=
c
(
COLID
)]
if
(
input
$
chBtrajInter
)
if
(
input
$
inSelTimeFreq
>
0
)
{
# NA's may be already present in the dataset'.
# Interpolate (linear) them with na.interpolate as well
if
(
locPos
)
s.cols
=
c
(
COLY
,
COLPOSX
,
COLPOSY
)
else
s.cols
=
c
(
COLY
)
loc.out
=
LOCinterpolate
(
loc.out
,
COLGR
,
COLID
,
COLRT
,
s.cols
,
input
$
inSelTimeFreq
,
T
)
# !!! 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)
}
}
# loc.out[, (s.cols) := lapply(.SD, na.interpolation), by = c(COLID), .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)
## Trim x-axis (time)
if
(
input
$
chBtimeTrim
)
{
if
(
input
$
chBtimeTrim
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment