Skip to content

Commit

Permalink
#19 Refactor the file/parameter upload section of the shiny app
Browse files Browse the repository at this point in the history
  • Loading branch information
julianstanley committed Aug 8, 2020
1 parent a8b077f commit 5317ca9
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 245 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Imports:
dplyr,
RColorBrewer,
cowplot
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
Suggests:
testthat,
vdiffr,
Expand Down
2 changes: 2 additions & 0 deletions inst/shinyApp/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ library(mongolite)
library(shinyjs)
library(plotly)
library(shinycssloaders)
library(DT)
library(gridExtra)
source(file.path("utils", "helpers.R"), local = TRUE)

ui <- navbarPage(
Expand Down
76 changes: 59 additions & 17 deletions inst/shinyApp/server/server_01_welcome.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ observeEvent(input$`use-upload`, {
update_sensor_lambda <- observeEvent(input$sensors, {
if (input$sensors %in% sensorNames) {
index <- match(input$sensors, sensorData$sensor_name)
updateNumericInput(session, inputId = "lambda1",
value = sensorData$lambda1_recommended[[index]])
updateNumericInput(session, inputId = "lambda2",
value = sensorData$lambda2_recommended[[index]])
updateNumericInput(session,
inputId = "lambda1",
value = sensorData$lambda1_recommended[[index]]
)
updateNumericInput(session,
inputId = "lambda2",
value = sensorData$lambda2_recommended[[index]]
)
}
})

Expand Down Expand Up @@ -241,24 +245,62 @@ output$sensorChars <- renderText({

# Custom Sensor Page ---------------------------------------------------
# Output the characteristics of the custom sensor
output$customChars <- output$customChars2 <- renderText({
# Make a sensor with custom characteristics
output$customChars <- output$customChars2 <- renderDT(
{
# Make a sensor with custom characteristics
sensor <- sensorInfo$sensor
type <- input$sensorType
# Create a specific sensor object
sensor <- makeSpecificSensor(
sensor, type,
input$midpoint
)

min_str <- switch(type, "redox" = "Rreduced", "pH" = "Rprotenated", "other" = "Rmin")
max_str <- switch(type, "redox" = "Roxidized", "pH" = "Rdeprotenated", "other" = "Rmax")

data.table(
Parameters = c("Sensor", min_str, max_str, "Dynamic Range"),
Values = c(
sensorInfo$sensor_name,
round(sensor@Rmin, 2), round(sensor@Rmax, 2),
round(sensor@Rmax / sensor@Rmin, 2)
)
)
},
options = list("pageLength" = 5, dom = "", searching = F, scrollX = T,
columnDefs = list(list(className = 'dt-center', targets = "_all"))),
rownames = FALSE,
width = "50%"
)

# Output the graph of R vs FractionMax of the custom sensor
output$plotFraction_Value <- output$plotFraction_Value2 <- renderPlot({
sensor <- sensorInfo$sensor

# Create a specific sensor object
sensor <- makeSpecificSensor(
sensor, input$sensorType,
input$midpoint
)
return(paste0(
"Sensor: ", sensorInfo$sensor_name, " | ",
"Rmin: ", round(sensor@Rmin, 2), " | ",
"Rmax: ", round(sensor@Rmax, 2), " | ",
"Dynamic range: ", round(sensor@Rmax / sensor@Rmin, 3)
fracMax <- plotFractionMax(sensor) +
theme(
aspect.ratio = 1,
text = element_text(size = 20)
)

R_Value <- data.frame(R = getR(sensor), Value = getProperty(
sensor,
getR(sensor)
))


value <- ggplot(R_Value, aes(x = R, y = Value)) +
geom_line() +
theme(
aspect.ratio = 1,
text = element_text(size = 20)
)

grid.arrange(fracMax, value, ncol = 2)

})

# Output the graph of R vs FractionMax of the custom sensor
output$plotFractionMax_custom <- output$plotFractionMax_custom2 <- renderPlot({
# Make a sensor with custom characteristics
sensor <- sensorInfo$sensor
Expand Down
6 changes: 6 additions & 0 deletions inst/shinyApp/ui/ui_01_welcome.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ tabPanel(
"Home",
useShinyjs(),
tags$style(appCSS),
tags$head(
tags$style(HTML("
th { display: none; }
td { font-size: 2em; }
"))
),
tags$div(
class = "jumbotron",
tags$div(
Expand Down
Loading

0 comments on commit 5317ca9

Please sign in to comment.