Skip to content

Commit

Permalink
Merge pull request #177 from ldecicco-USGS/master
Browse files Browse the repository at this point in the history
tests, stop button, Rdata
  • Loading branch information
ldecicco-USGS authored Apr 12, 2017
2 parents 55c9eb4 + b7f6c3b commit 3036bf8
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 6 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Imports:
data.table,
RColorBrewer,
stringi,
readxl
readxl,
tools
Suggests:
rmarkdown,
testthat,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ importFrom(stringi,stri_trans_totitle)
importFrom(tidyr,gather)
importFrom(tidyr,spread)
importFrom(tidyr,unite)
importFrom(tools,file_ext)
1 change: 1 addition & 0 deletions R/explore_endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @param browse use browser for map rendering
#' @export
#' @importFrom shiny runApp
#' @importFrom tools file_ext
#' @importFrom leaflet leaflet
#' @importFrom leaflet addLegend
#' @importFrom leaflet addCircles
Expand Down
2 changes: 2 additions & 0 deletions R/plot_tox_endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#' chem_site,
#' chem_info)
#' plot_tox_endpoints(chemicalSummary, filterBy = "Cell Cycle")
#' plot_tox_endpoints(chemicalSummary, category = "Chemical Class", filterBy = "PAH")
#' plot_tox_endpoints(chemicalSummary, category = "Chemical", filterBy = "Atrazine")
plot_tox_endpoints <- function(chemicalSummary,
category = "Biological",
filterBy = "All",
Expand Down
14 changes: 11 additions & 3 deletions inst/shiny/getData.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ rawData <- reactive({
if(!is.null(input$data)){

path <- file.path(input$data$datapath)

newPath <- paste0(input$data$datapath,"_",input$data$name)
newPath <- gsub(", ","_",newPath)

file.rename(from = path, to = newPath)

chem_data <- read_excel(newPath, sheet = "Data")
chem_info <- read_excel(newPath, sheet = "Chemicals")
chem_site <- read_excel(newPath, sheet = "Sites")
if(tools::file_ext(input$data$name) == "xlsx" |
tools::file_ext(input$data$name) == "xls"){
chem_data <- read_excel(newPath, sheet = "Data")
chem_info <- read_excel(newPath, sheet = "Chemicals")
chem_site <- read_excel(newPath, sheet = "Sites")
} else if(tools::file_ext(input$data$name) == "RData" |
tools::file_ext(input$data$name) == "rds"){
load(newPath)
}

rawData <- list(chem_data=chem_data,
chem_info=chem_info,
Expand Down
2 changes: 1 addition & 1 deletion inst/shiny/mapStuff.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ observe({
clearMarkers() %>%
clearControls() %>%
addCircleMarkers(lat=~dec_lat, lng=~dec_lon,
popup=paste0('<b>',mapData$`Short Name`,"</b><br/><table>",
popup=paste0('<b>',mapData$site,"</b><br/><table>",
"<tr><td>",maxEARWords,": </td><td>",sprintf("%.1f",mapData$meanMax),'</td></tr>',
"<tr><td>Number of Samples: </td><td>",mapData$nSamples,'</td></tr>',
# "<tr><td>Frequency: </td><td>",sprintf("%.1f",mapData$freq),'</td></tr>',
Expand Down
4 changes: 4 additions & 0 deletions inst/shiny/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ flags <- c( "OneAbove","Noisy","HitCall")

shinyServer(function(input, output,session) {

observe({
if (input$close > 0) stopApp()
})

source("getData.R",local=TRUE)$value

chemicalSummary <- reactive({
Expand Down
8 changes: 7 additions & 1 deletion inst/shiny/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ header <- dashboardHeader(title = "toxEval")

sidebar <- dashboardSidebar(
sidebarMenu(

tags$button(
id = 'close',
type = "button",
class = "btn action-button",
onclick = "setTimeout(function(){window.close();},500);", # close browser
"Stop ToxEval"
),
fileInput("data", "Load Excel File",multiple = FALSE),
radioButtons("radioMaxGroup", label = "",
choices = list("Group" = 1, "Chemical" = 2, "Class" = 3),
Expand Down
2 changes: 2 additions & 0 deletions man/plot_tox_endpoints.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 113 additions & 0 deletions tests/testthat/tests_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ test_that("Plotting stacked summaries", {

})

test_that("Plotting endpoints", {
testthat::skip_on_cran()

bioStackPlot <- suppressWarnings(plot_tox_endpoints(chemicalSummary,
category = "Biological",
filterBy = "Cell Cycle"))
expect_true(all(names(bioStackPlot$data) %in% c("site","category","endPoint",
"meanEAR")))

classStackPlot <- suppressWarnings(plot_tox_endpoints(chemicalSummary,
category = "Chemical Class", filterBy = "PAH"))
expect_true(all(names(classStackPlot$data) %in% c("site","category","endPoint",
"meanEAR")))

chemStackPlot <- suppressWarnings(plot_tox_endpoints(chemicalSummary, category = "Chemical", filterBy = "Atrazine"))
expect_true(all(names(chemStackPlot$data) %in% c("site","category","endPoint",
"meanEAR")))

})


test_that("Internal table functions", {
testthat::skip_on_cran()
Expand Down Expand Up @@ -130,4 +150,97 @@ test_that("Map stuff functions", {
category = "Biological")
expect_type(mapDataList, "list")
expect_equal(length(mapDataList), 2)
})

test_that("Table endpoint hits", {
testthat::skip_on_cran()

bt <- table_endpoint_hits(chemicalSummary, category = "Biological")
expect_type(bt, "list")
expect_true(all(names(bt$x$data) %in% c("endPoint","Nuclear Receptor","DNA Binding",
"Phosphatase","Steroid Hormone","Esterase")))

expect_error(table_endpoint_hits(chemicalSummary, category = "Class"))

ct <- table_endpoint_hits(chemicalSummary, category = "Chemical Class")
expect_type(ct, "list")

expect_true(all(names(ct$x$data) %in% c("endPoint","Antioxidant",
"Detergent Metabolites","Herbicide",
"Plasticizer")))

cht <- table_endpoint_hits(chemicalSummary, category = "Chemical")
expect_type(cht, "list")

expect_true(all(names(cht$x$data) %in% c("endPoint","Bisphenol A",
"4-Nonylphenol, branched","Triphenyl phosphate",
"Metolachlor","Atrazine")))
})

test_that("table_tox_endpoint", {
testthat::skip_on_cran()

bt <- table_tox_endpoint(chemicalSummary, category = "Biological")
expect_type(bt, "list")
expect_true("nSites" %in% names(bt$x$data))

expect_error(table_tox_endpoint(chemicalSummary, category = "Class"))

ct <- table_tox_endpoint(chemicalSummary, category = "Chemical Class")
expect_type(ct, "list")

expect_true(all(names(ct$x$data) %in% c(" ","Nuclear Receptor","DNA Binding",
"Phosphatase","Esterase","Steroid Hormone",
"Zebrafish")))

cht <- table_tox_endpoint(chemicalSummary, category = "Chemical")
expect_type(cht, "list")

expect_true(all(names(cht$x$data) %in% c(" ","Nuclear Receptor","DNA Binding",
"Phosphatase","Esterase","Steroid Hormone",
"Zebrafish")))
})


test_that("table_tox_sum", {
testthat::skip_on_cran()

bt <- table_tox_sum(chemicalSummary, category = "Biological")
expect_type(bt, "list")
expect_true(all(c("site","category","Hits.per.Sample","Individual.Hits","nSamples") %in% names(bt$x$data)))

expect_error(table_tox_sum(chemicalSummary, category = "Class"))

ct <- table_tox_sum(chemicalSummary, category = "Chemical Class")
expect_type(ct, "list")

expect_true(all(names(ct$x$data) %in% c("site","category","Hits.per.Sample","Individual.Hits","nSamples")))

cht <- table_tox_sum(chemicalSummary, category = "Chemical")
expect_type(cht, "list")

expect_true(all(names(cht$x$data) %in% c("site","category","Hits.per.Sample","Individual.Hits","nSamples")))
})

test_that("table_tox_rank", {
testthat::skip_on_cran()

bt <- table_tox_rank(chemicalSummary, category = "Biological")
expect_type(bt, "list")
expect_true("site" %in% names(bt$x$data))

expect_error(table_tox_rank(chemicalSummary, category = "Class"))

ct <- table_tox_rank(chemicalSummary, category = "Chemical Class")
expect_type(ct, "list")

expect_true(all(c("site","Antioxidant maxEAR","Antioxidant freq",
"Herbicide maxEAR","Herbicide freq",
"Detergent Metabolites maxEAR","Detergent Metabolites freq") %in% names(ct$x$data)))

cht <- table_tox_rank(chemicalSummary, category = "Chemical")
expect_type(cht, "list")

expect_true(all(c("site","Bisphenol A maxEAR","Bisphenol A freq",
"4-Nonylphenol, branched maxEAR") %in% names(cht$x$data)))
})

0 comments on commit 3036bf8

Please sign in to comment.