Commit c16da352 authored by dmattek's avatar dmattek

Added multiple columns for facetting

parent e30e1438
......@@ -36,9 +36,7 @@ myGgplotTraj = function(dt.arg,
plotlab.arg = NULL,
dt.stim.arg = NULL,
tfreq.arg = 1,
maxrt.arg = 60,
xaxisbreaks.arg = 10,
ylim.arg = c(0,1),
ylim.arg = NULL,
stim.bar.height.arg = 0.1,
stim.bar.width.arg = 0.5) {
p.tmp = ggplot(dt.arg,
......@@ -75,9 +73,10 @@ myGgplotTraj = function(dt.arg,
group = 1)
}
if (!is.null(ylim.arg))
p.tmp = p.tmp + coord_cartesian(ylim = ylim.arg)
p.tmp = p.tmp +
scale_x_continuous(breaks = seq(0, maxrt.arg, xaxisbreaks.arg)) +
coord_cartesian(ylim = ylim.arg) +
xlab(paste0(xlab.arg, "\n")) +
ylab(paste0("\n", ylab.arg)) +
ggtitle(plotlab.arg) +
......
......@@ -14,7 +14,7 @@ library(plotly)
options(shiny.maxRequestSize=30*1024^2)
source('auxfunc.R')
shinyServer(function(input, output) {
shinyServer(function(input, output, session) {
butCounter <- reactiveValues(
dataLoadNuc = isolate(ifelse(is.null(input$inFileNucLoad), 0, 1)),
......@@ -34,7 +34,7 @@ shinyServer(function(input, output) {
locColSel = locCols[locCols %like% 'ite'][1] # index 1 at the end in case more matches; select 1st
cat(locColSel, '\n')
selectInput('inSelSite', 'Select Grouping (e.g. Metadata_Site or Well):', locCols, width = '100%', selected = locColSel)
selectInput('inSelSite', 'Select FOV (e.g. Metadata_Site or Metadata_Series):', locCols, width = '100%', selected = locColSel)
})
output$varSelTrackLabel = renderUI({
......@@ -52,30 +52,86 @@ shinyServer(function(input, output) {
locColSel = locCols[locCols %like% 'ime'][1] # index 1 at the end in case more matches; select 1st
cat(locColSel, '\n')
selectInput('inSelTime', 'Select Time (e.g. RealTime):', locCols, width = '100%', selected = locColSel)
selectInput('inSelTime', 'Select X (e.g. RealTime):', locCols, width = '100%', selected = locColSel)
})
output$varSelMeas1 = renderUI({
cat(file=stderr(), 'UI varSelMeas1\n')
# This is main field to select plot facet grouping
# It's typically a column with the entire experimental description,
# e.g. in Yannick's case it's Stim_All_Ch or Stim_All_S.
# In Coralie's case it's a combination of 3 columns called Stimulation_...
output$varSelGroup = renderUI({
cat(file=stderr(), 'UI varSelGroup\n')
locCols = getDataNucCols()
locColSel = locCols[locCols %like% 'MeanIntensity'][1] # index 1 at the end in case more matches; select 1st
locColSel = locCols[locCols %like% 'timulation']
if (length(locColSel) == 0)
locColSel = locCols[locCols %like% 'ite'][1] # index 1 at the end in case more matches; select 1st
else if (length(locColSel) > 1) {
locColSel = locColSel[1]
}
cat(locColSel, '\n')
selectInput('inSelMeas1', 'Select 1st Measurement:', locCols, width = '100%', selected = locColSel)
# cat('UI varSelGroup::locColSel ', locColSel, '\n')
selectInput('inSelGroup', 'Select Grouping for Plotting (e.g. Site, Well, Channel):', locCols, width = '100%', selected = locColSel)
})
output$varSelRatio = renderUI({
cat(file=stderr(), 'UI varSelRatio\n')
checkboxInput('inSelRatio', 'Divide by:', 0)
output$varSelGroup2 = renderUI({
cat(file=stderr(), 'UI varSelGroup2\n')
locCols = getDataNucCols()
locColSel = locCols[locCols %like% 'timulation']
if (length(locColSel) == 0)
locColSel = locCols[locCols %like% 'ite'][1] # index 1 at the end in case more matches; select 1st
else if (length(locColSel) > 1) {
# updateCheckboxInput(session, 'inGroupMore1', value = 1)
locColSel = locColSel[2]
}
# cat('UI varSelGroup2::locColSel ', locColSel, '\n')
if(input$inGroupMore1) {
selectInput('inSelGroup2', 'Select Additional Grouping:', locCols, width = '100%', selected = locColSel)
} else {
disabled(selectInput('inSelGroup2', 'Select Additional Grouping:', locCols, width = '100%', selected = locColSel))
}
})
output$varSelGroup3 = renderUI({
cat(file=stderr(), 'UI varSelGroup2\n')
locCols = getDataNucCols()
locColSel = locCols[locCols %like% 'timulation']
if (length(locColSel) == 0)
locColSel = locCols[locCols %like% 'ite'][1] # index 1 at the end in case more matches; select 1st
else if (length(locColSel) > 1) {
# updateCheckboxInput(session, 'inGroupMore2', value = 1)
locColSel = locColSel[3]
}
# cat('UI varSelGroup3::locColSel ', locColSel, '\n')
if(input$inGroupMore2) {
selectInput('inSelGroup3', 'Select Additional Grouping:', locCols, width = '100%', selected = locColSel)
} else {
disabled(selectInput('inSelGroup3', 'Select Additional Grouping:', locCols, width = '100%', selected = locColSel))
}
})
output$varSelMeas1 = renderUI({
cat(file=stderr(), 'UI varSelMeas1\n')
locCols = getDataNucCols()
locColSel = locCols[locCols %like% 'Intensity'][1] # index 1 at the end in case more matches; select 1st
# cat(locColSel, '\n')
selectInput('inSelMeas1', 'Select Y:', locCols, width = '100%', selected = locColSel)
})
output$varSelMeas2 = renderUI({
cat(file=stderr(), 'UI varSelMeas2\n')
locCols = getDataNucCols()
locColSel = locCols[locCols %like% 'Intensity'][1] # index 1 at the end in case more matches; select 1st
cat(locColSel, '\n')
selectInput('inSelMeas2', 'Select 2nd Measurement:', locCols, width = '100%', selected = locColSel)
# cat(locColSel, '\n')
selectInput('inSelMeas2', 'Select 2nd operand:', locCols, width = '100%', selected = locColSel)
})
output$outPlot = renderUI({
......@@ -98,7 +154,6 @@ shinyServer(function(input, output) {
# make unique cell identifier based on metadata.site
cat(file=stderr(), 'userDataNucMod: in\n')
# dt = userDataNuc()
dt = dataInBoth()
colNameSite = input$inSelSite
colNameTrackLabel = input$inSelTrackLabel
......@@ -113,20 +168,6 @@ shinyServer(function(input, output) {
sep = "_")]
loc.colnames = colnames(dt)
if (sum(loc.colnames %like% 'Stimulation') == 0) {
dt[, metadata.site.stim := get(colNameSite)]
} else {
dt[, metadata.site.stim := paste(
sprintf('%02d', get(colNameSite)),
': ',
Stimulation_duration,
' ',
Stimulation_intensity,
' ',
Stimulation_treatment,
sep = ''
)]
}
cat(file=stderr(), 'userDataNucMod: out\n')
return(dt)
......@@ -146,26 +187,35 @@ shinyServer(function(input, output) {
observeEvent(input$butReset, {
reset("inFileNucLoad") # reset is a shinyjs function
reset("inFileStimLoad") # reset is a shinyjs function
reset("inGroupMore1") # reset is a shinyjs function
reset("inGroupMore2") # reset is a shinyjs function
})
dataInBoth <- reactive({
cat(file=stderr(), 'dataInBoth: in\n')
locInGen = input$butDataGen
locInLoadNuc = ifelse(is.null(input$inFileNucLoad), 0, isolate(butCounter$dataLoadNuc) + 1)
locInLoadStim = ifelse(is.null(input$inFileStimLoad), 0, isolate(butCounter$dataLoadStim) + 1)
locButLoadNuc = isolate(butCounter$dataLoadNuc)
locButLoadStim = isolate(butCounter$dataLoadStim)
locButGen = isolate(butCounter$dataGen)
cat("butCounter$dataGen: ", locButGen, "\nbutCounter$dataLoadNuc: ", locButLoadNuc, "\nbutCounter$locButLoadStim: ", locButLoadStim, "\n")
locInLoadNuc = ifelse(is.null(input$inFileNucLoad), 0, locButLoadNuc + 1)
locInLoadStim = ifelse(is.null(input$inFileStimLoad), 0, locButLoadStim + 1)
cat(file=stderr(), "dataInBoth\ninGen: ", locInGen, "\ninLoadNuc: ", locInLoadNuc, "\ninLoadStim: ", locInLoadStim, "\n")
cat(file=stderr(), "dataInBoth\n1: ", locInGen, "\n2: ", locInLoadNuc, "\n3: ", locInLoadStim, "\n")
# isolate the checks of counter reactiveValues
# as we set the values in this same reactive
if (locInLoadNuc != isolate(butCounter$dataLoadNuc)) {
if (locInLoadNuc != locButLoadNuc) {
cat(file=stderr(), "dataInBoth if inFileNucLoad\n")
dm = userDataNuc()
# no need to isolate updating the counter reactive values!
butCounter$dataLoad <- locInLoadNuc
} else if (locInGen != isolate(butCounter$dataGen)) {
} else if (locInGen != locButGen) {
cat(file=stderr(), "dataInBoth if inDataGen\n")
dm = userDataGen()
cat(colnames(dm))
......@@ -189,9 +239,10 @@ shinyServer(function(input, output) {
}
dt.nuc = (userDataNucMod())
dt.nuc = userDataNucMod()
locInLoadStim = isolate(input$inFileStimLoad)
if (is.null(dt.nuc) && is.null(locInLoadStim)) {
cat(file=stderr(), 'trajPlot: Data not yet loaded\n')
......@@ -210,29 +261,35 @@ shinyServer(function(input, output) {
loc.time = isolate(input$inSelTime)
loc.meas.1 = isolate(input$inSelMeas1)
if (isolate(input$inSelRatio)) {
# create an expression for faceting (max 3 fields)
loc.facet.group = isolate(input$inSelGroup)
if (isolate(input$inGroupMore1)) {
loc.facet.group = paste0(loc.facet.group, ' + ', isolate(input$inSelGroup2))
}
if (isolate(input$inGroupMore2)) {
loc.facet.group = paste0(loc.facet.group, ' + ', isolate(input$inSelGroup3))
}
# cat("loc.facet.group: ", loc.facet.group, "\n")
# create expression for plotting Y-axis
loc.math = isolate(input$inSelMath)
if (loc.math != '') {
loc.meas.2 = isolate(input$inSelMeas2)
loc.y.arg = paste0(loc.meas.1, ' / ', loc.meas.2)
loc.y.arg = paste0(loc.meas.1, loc.math, loc.meas.2)
} else
loc.y.arg = loc.meas.1
cat(loc.y.arg)
# cat("loc.y.arg", loc.y.arg, "\n")
p.out = myGgplotTraj(
dt.arg = dt.nuc,
x.arg = loc.time,
y.arg = loc.y.arg,
group.arg = "trackObjectsLabelUni",
facet.arg = 'metadata.site.stim',
# xlab.arg = "Time (min)",
# ylab.arg = loc.y.arg,
# plotlab.arg = "Raw data from illumination-corrected images",
facet.arg = loc.facet.group,
dt.stim.arg = dt.stim,
tfreq.arg = 1,
maxrt.arg = 120,
xaxisbreaks.arg = 10,
facet.ncol.arg = loc.facet.ncol.arg,
ylim.arg = c(0, 1.2),
stim.bar.height.arg = 0.05,
stim.bar.width.arg = 1
)
......@@ -240,10 +297,22 @@ shinyServer(function(input, output) {
#ggplotly(p.out)
cat(file=stderr(), 'trajPlot: out\n')
# This is required to avoid
# "Warning: Error in <Anonymous>: cannot open file 'Rplots.pdf'"
# When running on a server. Based on:
# https://github.com/ropensci/plotly/issues/494
if (names(dev.cur()) != "null device") dev.off()
pdf(NULL)
return(ggplotly(p.out))
p.out.ly = plotly_build(p.out)
# Custom tooltip
# p.out.ly$x$data[[1]]$text <- sprintf("t: %d <br>y: %.2f <br>id: %s <br>s: %s",
# dt.nuc[[loc.time]],
# dt.nuc[[loc.y.arg]], dt.nuc[['trackObjectsLabelUni']],
# dt.nuc[[loc.facet.group]])
return(p.out.ly)
})
})
......
......@@ -31,23 +31,40 @@ shinyUI(fluidPage(
accept = c('text/csv', 'text/comma-separated-values,text/plain')
),
h4("Plot format"),
fluidRow(
column(4,
numericInput('inFacetNcol', '#Columns:', value = 4, min = 1, width = '100px', step = 1)),
column(4,
numericInput('inPlotHeight', 'Height [px]:', value = 800, min = 100, width = '100px', step = 50)),
column(4,
numericInput('inPlotWidth', 'Width [%]:', value = 100, min = 10, max = 100, width = '100px', step = 10))
),
actionButton("butReset", "Reset file input"),
actionButton('butDataGen', 'Generate artificial dataset'),
actionButton('butGo', 'Go!')),
column(4, offset = 1,
column(3, offset = 1,
uiOutput('varSelSite'),
uiOutput('varSelTrackLabel'),
uiOutput('varSelTime'),
uiOutput('varSelMeas1'),
uiOutput('varSelRatio'),
radioButtons('inSelMath', 'Math operation 1st and 2nd meas.:', c('None' = '',
'Divide' = " / ",
'Sum' = " + ",
'Multiply' = " * ",
'Subtract' = ' - ')),
uiOutput('varSelMeas2')),
column(2, offset = 1,
numericInput('inFacetNcol', 'No. of plot columns:', value = 4, min = 1, width = '150px', step = 1),
numericInput('inPlotHeight', 'Plot Height [px]:', value = 400, min = 100, width = '150px', step = 50),
numericInput('inPlotWidth', 'Plot Width [%]:', value = 100, min = 10, max = 100, width = '150px', step = 10))
),
column(3, offset = 1,
uiOutput('varSelGroup'),
checkboxInput('inGroupMore1', 'More grouping?'),
uiOutput('varSelGroup2'),
checkboxInput('inGroupMore2', 'More grouping?'),
uiOutput('varSelGroup3'))
),
br(),
uiOutput('outPlot')
))
......
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