Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
shinyQC/app.R
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
185 lines (137 sloc)
5.33 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################### | |
## ## | |
## shiny QC ## | |
## ## | |
################################################### | |
# problem: does not update when path is updated | |
# clean global environment | |
wipe_global_env <- TRUE | |
if(wipe_global_env) rm(list=ls(envir = .GlobalEnv), envir = .GlobalEnv) | |
assign("LOCAL_DB", F, env = .GlobalEnv) | |
if (Sys.info()["user"] == "cedlich") { | |
assign("DEBUG", TRUE, env = .GlobalEnv) | |
} else { | |
assign("DEBUG", FALSE, env = .GlobalEnv) | |
} | |
# machine-dependent mount point | |
if (Sys.info()["user"] == "cedlich" && LOCAL_DB) { | |
store_age <- "~/Documents/LocalDB/Projects/Metabolomics/QC" | |
} else { | |
store_age <- file.path(ifelse(.Platform$OS.type=="unix", "/Volumes/group_metabolomics", "Z:"), "group", "#Projects", "Metabolomics/ShinyQC") | |
} | |
assign("STORE_AGE", store_age, env = .GlobalEnv) | |
assign("PLOT_Y_VAR", c("DELTA_MZ", "DELTA_RT", "mSigma", "DELTA_CCS", "PEAK_AREA", "AREA_OVER_HEIGHT", "HEIGHT", "RT", "MZ"), env = .GlobalEnv) | |
assign("PLOT_X_VAR", c("EXP_ID", "DATE", "DATE2"), env = .GlobalEnv) | |
message(sprintf("DEBUG mode = %s", DEBUG)) | |
message(sprintf("Store path = %s", STORE_AGE)) | |
message("Loading libraries") | |
# libraries | |
suppressPackageStartupMessages(library(shinyWidgets)) | |
suppressPackageStartupMessages(library(tidyselect)) | |
suppressPackageStartupMessages(library(shinyalert)) | |
suppressPackageStartupMessages(library(foreach)) | |
suppressPackageStartupMessages(library(readxl)) | |
suppressPackageStartupMessages(library(RColorBrewer)) | |
suppressPackageStartupMessages(library(shinythemes)) | |
suppressPackageStartupMessages(library(magrittr)) | |
suppressPackageStartupMessages(library(tidyverse)) | |
suppressPackageStartupMessages(library(shiny)) | |
suppressPackageStartupMessages(library(shinyBS)) | |
suppressPackageStartupMessages(library(DT)) | |
# allow upload up to 500 MB | |
options(shiny.maxRequestSize = 500*1024^2) | |
cat(getwd(), "\n") | |
message("Sourcing scripts") | |
source("Scripts/qc_parser.R") | |
source("Scripts/simple_plotter.R") | |
source("Scripts/helper/shiny_input_with_pref.R") | |
# code for non-reactive functions | |
# for (pathdir in list.files("Scripts") %>% setdiff("old")) { | |
# for (f in list.files(file.path("Scripts", pathdir), pattern="*.R")) { | |
# fp <- file.path("Scripts", pathdir, f) | |
# # print(sprintf("Sourcing %s", fp)) | |
# source(fp) | |
# } | |
# } | |
# preferences for shiny widgets | |
assign("MY_SHINY_PREFERENCES", | |
if(file.exists("shiny_preferences.RDS")) my_read_shiny_prefs() else list(), | |
envir = .GlobalEnv | |
) | |
message("Starting app") | |
ui <- | |
fluidPage( | |
# https://community.rstudio.com/t/force-selectinput-to-wrap-text/88185 | |
htmltools::tags$head( | |
htmltools::tags$style( | |
type='text/css', | |
".selectize-input { word-wrap : break-word;} | |
.selectize-input { word-break: break-word;} | |
.selectize-dropdown {word-wrap : break-word;} | |
" | |
)), | |
navbarPage( | |
id = "fluxer_navbarpage", | |
title = "Quincy", | |
theme = shinytheme("yeti"), | |
tabPanel("Input", source(file.path("ui_code", "0100_ui_infile.R"), local = TRUE)$value), | |
tabPanel("Plot", source(file.path("ui_code", "0200_ui_plot1.R"), local = TRUE)$value) | |
# | |
) | |
) | |
server <- function(input, output, session) { | |
# initialise reactive variables | |
my_store_path <- reactiveValues() | |
my_raw_data <- reactiveValues() | |
my_data <- reactiveValues() | |
#### infile #### | |
source(file.path("server_code", "0101_server_infile_store.R"), local = TRUE)$value | |
# source(file.path("server_code", "0102_server_infile_select_exp.R"), local = TRUE)$value | |
source(file.path("server_code", "0200_server_plot1.R"), local = TRUE)$value | |
source(file.path("server_code", "0201_server_exp_exclude.R"), local = TRUE)$value | |
#### outfile #### | |
# source(file.path("server_code", "1001_server_outfile.R"), local = TRUE)$value | |
# source(file.path("server_code", "1002_server_outfile_old.R"), local = TRUE)$value | |
#### pref #### | |
output$pref_save = downloadHandler( | |
filename = "shiny_preferences.RDS", | |
content = function(file) { | |
my_shiny_pref( | |
isolate(reactiveValuesToList(input)) | |
) %>% | |
saveRDS(file) | |
} | |
) | |
observeEvent( | |
input$pref_load, | |
{ | |
assign("MY_SHINY_PREFERENCES", | |
my_read_shiny_prefs(input$pref_load$datapath), | |
envir = .GlobalEnv | |
) | |
my_pref_update(my_pref_update() + 1) | |
} | |
) | |
#### exit #### | |
onStop(function() { | |
env = parent.env(environment()) | |
ls(envir = env) %>% | |
## .. excluding e.g. session" and "output" | |
setdiff(c("session", "output", "my_pref_update")) %>% | |
## object in a list | |
mget(envir = env) %>% | |
## keep only reactive values | |
subset(., subset = sapply(., is.reactivevalues)) %>% | |
## convert reactive values | |
sapply(function(z) isolate(reactiveValuesToList(z)), simplify=F) %>% | |
## assign to global environment | |
list2env(envir = .GlobalEnv) | |
dirname = "server_code/" | |
# for( fname in list.files(dirname , pattern = "*\\.[rR]$")) source_functions_only2(file.path(dirname, fname)) | |
cat("Session stopped\n") | |
cat("Type `save(list=ls(), file='tmp.RData')` to save state variables in your current working directory\n") | |
cat("Find out what current working directory by typing `getwd()`\n") | |
} | |
) | |
} | |
shinyApp(ui, server) |