Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/basic tests #5

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
^renv$
^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
25 changes: 25 additions & 0 deletions .github/actions/renv-plus/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The MIT License (MIT)
=====================

Copyright © 2021 RStudio and others.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
32 changes: 32 additions & 0 deletions .github/actions/renv-plus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# setup-renv

[![RStudio community](https://img.shields.io/badge/community-github--actions-blue?style=social&logo=rstudio&logoColor=75AADB)](https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions)

This action installs dependencies for the current R environment based on the renv lockfile in the repository by:

- Installing [renv](https://rstudio.github.io/renv/articles/renv.html)
- Setting up a dependency cache using [actions/cache](https://github.com/actions/cache).

# Usage

Inputs available

- `cache-version` - default `1`. If you need to invalidate the existing cache pass any other number and a new cache will be used.

Basic:
```yaml
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-renv@v2
with:
cache-version: 2
```

# License

The scripts and documentation in this project are released under the [MIT License](LICENSE)

# Contributions

Contributions are welcome!
48 changes: 48 additions & 0 deletions .github/actions/renv-plus/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: 'setup-renv'
description: 'Action to setup renv and install R dependencies in the lockfile'
author: 'Jim Hester'
inputs:
restore-args:
description: 'Arguments passed to renv::restore()'
default: ''
cache-version:
description: 'The version of the cache, change this from the default (1) to start over with a fresh cache'
required: true
default: 1
runs:
using: "composite"
steps:
- name: Set RENV_PATHS_ROOT
shell: bash
run: |
echo "RENV_PATHS_ROOT=${{ runner.temp }}/renv" >> $GITHUB_ENV
- name: Install and activate renv
run: |
install.packages("renv")
renv::activate()
shell: Rscript {0}

- name: Get R and OS version
id: get-version
run: |
cat("##[set-output name=os-version;]", sessionInfo()$running, "\n", sep = "")
cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "")
shell: Rscript {0}

- name: Restore Renv package cache
uses: actions/cache@v2
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}-${{ hashFiles('renv.lock') }}
restore-keys: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}-

- name: Install renv dependencies
run: renv::restore(${{ inputs.restore-args }})
shell: Rscript {0}

- name: Don't use tar 1.30 from Rtools35 to store the cache
shell: bash
run: |
if command -v /c/Rtools/bin/tar && /c/Rtools/bin/tar --version | grep -q 'tar (GNU tar) 1.30'
then echo 'C:/Program Files/Git/usr/bin' >> $GITHUB_PATH
fi
57 changes: 57 additions & 0 deletions .github/workflows/test-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@


# Workflow derived from https://github.com/rstudio/shinytest2/tree/main/actions/test-app/example-test-app-description.yaml
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: Test app w/ DESCRIPTION

jobs:
test-app:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-latest, r: release}

env:
GITHUB_PAT: ${{ secrets.EXTERNAL_GITHUB_TOKEN }}
GITLAB_PAT: ${{ secrets.GITLAB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- name: Install system dependencies
run: |
sudo apt-get install libcurl4-openssl-dev libv8-dev

- uses: ./.github/actions/renv-plus
with:
cache-version: 2
restore-args: 'exclude = "mapDataAccess"'

- name: Install extra dependencies
run: |
install.packages("shinytest2")
shell: Rscript {0}

- uses: rstudio/shinytest2/actions/test-app@v1
with:
path: "."
4 changes: 4 additions & 0 deletions FREDA.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
3 changes: 2 additions & 1 deletion Observers/groups_observers.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ observeEvent(input$add_group, {

updateTextInput(session, "group_name", value = "")
updatePickerInput(session, "group_samples", selected = setdiff(sample_names(), c(unlist(revals$groups_list), input$group_samples)))


exportTestValues(groups_list = revals$groups_list)
})

# shinyjs observer which disables input if selection is not valid
Expand Down
48 changes: 22 additions & 26 deletions Observers/preprocess_observers.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ observeEvent(input$preprocess_click, {
for(i in 1:length(valence_list)){
V <- valence_list[[i]]
for(name in names(V)){
print(V[[name]])
valence_df[i,name] <- V[[name]]
}
}
Expand Down Expand Up @@ -93,50 +92,41 @@ observeEvent(input$preprocess_click, {
revals$warningmessage_preprocess$makeobject_error <<- sprintf("<p style = 'color:red'>%s</p>", msg)
})

if(!exists('msg')) revals$uploaded_data <- temp
if(!exists('msg')) {
revals$uploaded_data <- temp
exportTestValues(uploaded_data_processed = revals$uploaded_data)
}
})

# post mortem test object
# test_uploaded_data <<- revals$peakData2

if (isTRUE(getOption("shiny.testmode"))) {
exportTestValues(peakData2 = revals$peakData2)
}

}, priority = 10) # End action button event

# Creates two reactive variables for continuous and categorical variables which are used to display separate tables
# Note: dependent on preprocess click and the user-specified calculations
observeEvent(input$preprocess_click, {
# Error handling: revals$uploaded_data must have a non-NULL Kendrick Mass column name
#req(!is.null(attr(revals$uploaded_data, 'cnames')$kmass_cname))
req(input$tests)

# Get csv file of all possible calculation column names
possible_calc_cnames <- read_csv("calculation_variables.csv") %>% as.data.frame(stringsAsFactors = FALSE)

# Get column names from revals$uploaded_data's e_meta
actual_cnames <- colnames(revals$uploaded_data$e_meta)

# Find all columns with names that match names for calculated columns
v_index <- which(possible_calc_cnames[,1] %in% actual_cnames)
v_index <- which(names(PREPROCESS_CALC_VARS) %in% actual_cnames)

# Save calculation column names from above and their display names
intersect <- possible_calc_cnames[v_index,]
present_vars <- PREPROCESS_CALC_VARS[v_index]

# get numeric columns
numeric_cols <- revals$uploaded_data$e_meta %>%
dplyr::select(which(sapply(.[intersect[,1]], is.numeric))) %>%
dplyr::select(which(sapply(.[,names(present_vars)], is.numeric))) %>%
names()

# get categorical columns
categorical_cols <- revals$uploaded_data$e_meta %>%
dplyr::select(which(!sapply(.[intersect[,1]], is.numeric))) %>%
dplyr::select(which(!sapply(.[names(present_vars)], is.numeric))) %>%
names()

#set reactive variables for observers
revals$numeric_cols <- intersect %>% filter(ColumnName %in% numeric_cols)
revals$categorical_cols <- intersect %>% filter(ColumnName %in% categorical_cols)
revals$numeric_cols <- present_vars[names(present_vars) %in% numeric_cols]
revals$categorical_cols <- present_vars[names(present_vars) %in% categorical_cols]

})

Expand Down Expand Up @@ -164,18 +154,24 @@ observeEvent(input$preprocess_dismiss,{

req(c(revals$numeric_cols, revals$categorical_cols))

if(isTRUE(nrow(revals$numeric_cols) > 0)){
columns <- summaryPreprocess(isolate(revals$uploaded_data), revals$numeric_cols) %>% colnames()
if(isTRUE(length(revals$numeric_cols) > 0)){
tmp_num_table <- summaryPreprocess(isolate(revals$uploaded_data), revals$numeric_cols)

revals$preprocess_tables$numeric <- summaryPreprocess(isolate(revals$uploaded_data), revals$numeric_cols) %>%
revals$preprocess_tables$numeric <- tmp_num_table %>%
datatable(options = list(dom = "t", pageLength = nrow(.))) %>%
formatRound(columns, digits = 2)
formatRound(colnames(tmp_num_table), digits = 2)

# __SHINYTEST__
exportTestValues(numeric_table = tmp_num_table)
}

if(isTRUE(nrow(revals$categorical_cols) > 0)){
if(isTRUE(length(revals$categorical_cols) > 0)){
revals$preprocess_tables$categorical <- summaryPreprocess(revals$uploaded_data, revals$categorical_cols, categorical = TRUE)

# __SHINYTEST__
exportTestValues(categorical_table = revals$preprocess_tables$categorical)
}

})

# For numeric columns:
Expand Down
1 change: 1 addition & 0 deletions Observers/startup_observers.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ observe({

# establish minio connection if we are pulling cloud resources
if(any(names(query) %in% VALID_MINIO_HEADER_PARAMS)) {
library(mapDataAccess)
minio_con <<- mapDataAccess::map_data_connection("./cfg/minio_config.yml")
}

Expand Down
2 changes: 2 additions & 0 deletions Observers/upload_observers.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ observeEvent(input$upload_click, {
shinyjs::show('ok_idcols')

revals$uploaded_data <- res

exportTestValues(uploaded_data = res)
}

}) # End peakData creation
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# FREDA
<!-- badges: start -->
[![tests](https://github.com/EMSL-computing/FREDA/actions/workflows/test-app.yaml/badge.svg)](https://github.com/EMSL-computing/FREDA/actions/workflows/test-app.yaml)
<!-- badges: end -->

***

Expand Down
38 changes: 36 additions & 2 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ library(readr)
library(plotly)
library(DT)
library(shinycssloaders)
library(mapDataAccess)

# uncomment either library() or load_all() if you need to load kegg
library(KeggData)
Expand All @@ -36,7 +35,11 @@ kendrick_opts_info <- 'The base compound(s) used to calculate the Kendrick Mass.
dt_checkmark <- '<span class="glyphicon glyphicon-ok" style="color:deepskyblue"></span>'
dt_minus <- '<span class="glyphicon glyphicon-minus"></span>'

ttip_text = list("plot_save"="Save the last created plot", "plot_review"="Review saved plots", "page_help"="How do I use this page?")
ttip_text = list(
"plot_save"="Save the last created plot",
"plot_review"="Review saved plots",
"page_help"="How do I use this page?"
)

#------ Download Example Data ---------#
example_edata <- read_csv('Data/example12T_edata.csv') %>% as.data.frame(stringsAsFactors = FALSE)
Expand All @@ -46,6 +49,37 @@ calc_vars <- read_csv('calculation_variables.csv') %>% as.data.frame(stringsAsFa
# determines when 'large data' options are triggered
max_cells <- 2000000

PREPROCESS_CALC_VARS <- list(
"ColumnName" = "DisplayName",
"OtoC_ratio" = "O:C Ratio",
"HtoC_ratio" = "H:C Ratio",
"NtoC_ratio" = "N:C Ratio",
"PtoC_ratio" = "P:C Ratio",
"NtoP_ratio" = "N:P Ratio",
"NOSC" = "NOSC",
"GFE" = "Gibbs Free Energy",
"AI" = "Aromaticity",
"AI_Mod" = "Modified Aromaticity",
"DBE" = "DBE",
"DBE_O" = "DBE - O",
"DBE_AI" = "DBE - AI",
"ElComposition" = "Elemental Composition",
"bs1_class" = "Compound Classes Using bs1",
"bs2_class" = "Compound Classes Using bs2",
"bs3_class" = "Compound Classes Using bs3"
)

BASE_COMPS <- c("CH2", "CO2", "H2", "H2O", "CHO")

.extra_kmass <- lapply(BASE_COMPS, function(x) sprintf("Kendrick Mass (Base %s)", x))
names(.extra_kmass) <- paste0("kmass.", BASE_COMPS)

.extra_kdefect <- lapply(BASE_COMPS, function(x) sprintf("Kendrick Defect (Base %s)", x))
names(.extra_kdefect) <- paste0("kdefect.", BASE_COMPS)

PREPROCESS_CALC_VARS <- c(PREPROCESS_CALC_VARS, .extra_kmass, .extra_kdefect)

# Info text for things such as warnings
info_text = list(
COREMS_UPLOAD_ERROR = "There was an error retrieving your Core-MS files: %s",
COREMS_UPLOAD_NOSAMPS = "No files found in the cloud location specified by 'corems-prefix' in the URL.",
Expand Down
Loading