Skip to content

Commit 9aae160

Browse files
author
Jan Červený
committed
Added graph zooming funcionality
-Added double click to zoom on selected range -Added posibilty to dowload analysis (growth rates calculations)
1 parent 3300eae commit 9aae160

1 file changed

Lines changed: 74 additions & 5 deletions

File tree

app.R

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ source('DB-connect.R', echo = FALSE)
2020
dataColumnNames <- readRDS('data/dataColumnNames.rds')
2121

2222
server <- function(input, output, session) {
23+
rangesView <- reactiveValues(x = NULL, y = NULL)
24+
rangesProcessing <- reactiveValues(x = NULL, y = NULL)
2325
observeEvent(input$send, {
2426
updateActionButton(
2527
session, 'regSend',
@@ -28,6 +30,26 @@ server <- function(input, output, session) {
2830
},
2931
ignoreNULL = TRUE
3032
)
33+
observeEvent(input$dataViewPlot_dblClick, {
34+
brush <- input$dataViewPlot_brush
35+
if (!is.null(brush)) {
36+
rangesView$x <- c(brush$xmin, brush$xmax)
37+
rangesView$y <- c(brush$ymin, brush$ymax)
38+
} else {
39+
rangesView$x <- NULL
40+
rangesView$y <- NULL
41+
}
42+
})
43+
observeEvent(input$dataProcessingPlot_dblClick, {
44+
brush <- input$dataProcessingPlot_brush
45+
if (!is.null(brush)) {
46+
rangesProcessing$x <- c(brush$xmin, brush$xmax)
47+
rangesProcessing$y <- c(brush$ymin, brush$ymax)
48+
} else {
49+
rangesProcessing$x <- NULL
50+
rangesProcessing$y <- NULL
51+
}
52+
})
3153
# File input ====
3254
dataInput <- reactive({
3355
if (is.null(input$dataFile) || (input$dataFile$type != 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')) {
@@ -87,6 +109,37 @@ server <- function(input, output, session) {
87109
}
88110
}
89111
)
112+
# Analysis file download ====
113+
output$downloadAnalysis <- downloadHandler(
114+
# This function returns a string which tells the client
115+
# browser what name to use when saving the file.
116+
filename = function() {
117+
paste(input$dataFile$name)
118+
}
119+
,
120+
# This function should write data to a file given to it by
121+
# the argument 'file'.
122+
content = function(file) {
123+
# Write to a file specified by the 'file' argument
124+
if (input$dataFile$type ==
125+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
126+
withProgress(
127+
message = "Writing processed data...",
128+
value = 0.4,
129+
{
130+
pbrDataFile <- loadWorkbook(file = input$dataFile$datapath)
131+
addWorksheet(pbrDataFile, 'TidyData')
132+
writeData(pbrDataFile, 'TidyData', dataProcessed())
133+
addWorksheet(pbrDataFile, 'Analysis')
134+
writeData(pbrDataFile, 'Analysis', growthRates())
135+
saveWorkbook(pbrDataFile, input$dataFile$datapath, overwrite = TRUE)
136+
incProgress(0.4)
137+
file.copy(input$dataFile$datapath, file)
138+
}
139+
)
140+
}
141+
}
142+
)
90143
# Growth Rates calculataion ====
91144
growthRates <- reactive({
92145
withProgress(
@@ -147,7 +200,7 @@ server <- function(input, output, session) {
147200
output$dataViewPlot <- renderPlot({
148201
data <- dataProcessed()
149202
if (!is.null(data)) {
150-
plot(x = data$time, y = data[[dataColumnNames$X[match(input$dataColumn, dataColumnNames$Y)]]], xlab = 'Experiment duration, h', ylab = 'Optical density, AU')
203+
plot(x = data$time, y = data[[dataColumnNames$X[match(input$dataColumn, dataColumnNames$Y)]]], xlim = rangesView$x, ylim = rangesView$y, xlab = 'Experiment duration, h', ylab = 'Optical density, AU')
151204
}
152205
})
153206

@@ -166,7 +219,7 @@ server <- function(input, output, session) {
166219
s1 = NULL
167220
s2 = input$dataProcessingTable_rows_selected
168221
gRates <- growthRates()
169-
plot(x = gRates$time, y = gRates$Dt, xlab = "Experiment duration, h", ylab = "Doubling time, h")
222+
plot(x = gRates$time, y = gRates$Dt, xlim = rangesProcessing$x, ylim = rangesProcessing$y, xlab = "Experiment duration, h", ylab = "Doubling time, h")
170223
if (length(s1)) {
171224
points(gRates[s1, , drop = FALSE], pch = 19, cex = 1, col = 'green')
172225
}
@@ -185,7 +238,7 @@ server <- function(input, output, session) {
185238

186239
ui <- fluidPage(
187240
tags$head(includeScript('google-analytics.js')),
188-
titlePanel("", windowTitle = "Tidy Up Data"),
241+
titlePanel("", windowTitle = "PBR Data Analysis"),
189242
sidebarLayout(
190243
# Sidebar panel ====
191244
sidebarPanel(
@@ -237,6 +290,9 @@ ui <- fluidPage(
237290
'right',
238291
options = list(container = 'body')
239292
)
293+
),
294+
fluidRow(
295+
downloadButton('downloadAnalysis', "Download")
240296
)
241297
),
242298
width = 3
@@ -254,7 +310,14 @@ ui <- fluidPage(
254310
em(textOutput('fileSize')),
255311
br(),
256312
textOutput('dataDim'),
257-
plotOutput('dataViewPlot', width = '90%')
313+
plotOutput('dataViewPlot',
314+
width = '90%',
315+
dblclick = 'dataViewPlot_dblClick',
316+
brush = brushOpts(
317+
id = 'dataViewPlot_brush',
318+
resetOnNew = TRUE
319+
)
320+
)
258321
),
259322
tabPanel(
260323
"Data Analysis",
@@ -267,7 +330,13 @@ ui <- fluidPage(
267330
),
268331
column(
269332
8,
270-
plotOutput('dataProcessingPlot')
333+
plotOutput('dataProcessingPlot',
334+
dblclick = 'dataProcessingPlot_dblClick',
335+
brush = brushOpts(
336+
id = 'dataProcessingPlot_brush',
337+
resetOnNew = TRUE
338+
)
339+
)
271340
)
272341
)
273342
),

0 commit comments

Comments
 (0)