diff --git a/.Rbuildignore b/.Rbuildignore
index d821302..d19fac6 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -2,3 +2,5 @@
^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
+^data-raw$
+^LICENSE\.md$
diff --git a/.gitignore b/.gitignore
index 6271a80..140614e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,4 +7,5 @@ renv/library/
renv/staging/
renv/cache/
inst/doc
+.Rprofile
.Renviron
diff --git a/DESCRIPTION b/DESCRIPTION
index f1cb17f..0f4b541 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -8,31 +8,45 @@ Authors@R:
email = "vsriram@fredhutch.org",
role = c("aut"),
comment = c(ORCID = "0000-0003-3759-2911")),
- person(given = "Scott",
- family = "Chamberlain",
- email = "sachamber@fredhutch.org",
+ person(given = "Sean",
+ family = "Kross",
+ email = "skross@fredhutch.org",
role = c("ctb", "cre"),
- comment = c(ORCID = "0000-0003-1444-9135")),
+ comment = c(ORCID = "0000-0001-5215-0316")),
person(given = "Monica",
family = "Gerber",
email = "mgerber@fredhutch.org",
- role = "ctb",
+ role = c("ctb"),
comment = c(ORCID = "0000-0001-9878-9166")),
- person(given = "Sean",
- family = "Kross",
- email = "skross@fredhutch.org",
+ person(given = "Scott",
+ family = "Chamberlain",
+ email = "sachamber@fredhutch.org",
role = c("ctb"),
- comment = c(ORCID = "0000-0001-5215-0316")))
+ comment = c(ORCID = "0000-0003-1444-9135"))
+ )
Description: Oncarto (Oncology Cartographer) is an R package / Shiny dashboard
developed by the Fred Hutch Data Science Lab (DaSL) for the
automated integration and visualization of publicly available cancer
incidence data for the Fred Hutch Cancer Center catchment area.
-License: MIT
+License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Suggests:
knitr,
- rmarkdown
+ rmarkdown,
+ testthat (>= 3.0.0)
VignetteBuilder: knitr
+Imports:
+ dplyr,
+ htmltools,
+ leaflet,
+ sf,
+ shiny,
+ shinycssloaders,
+ shinydashboard,
+ tigris
+Depends:
+ R (>= 2.10)
+Config/testthat/edition: 3
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..8842cc9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,2 @@
+YEAR: 2024
+COPYRIGHT HOLDER: oncarto authors
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..2ebbb3f
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,21 @@
+# MIT License
+
+Copyright (c) 2024 oncarto authors
+
+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.
diff --git a/NAMESPACE b/NAMESPACE
index d75f824..54cf524 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1 +1,39 @@
-exportPattern("^[[:alpha:]]+")
+# Generated by roxygen2: do not edit by hand
+
+export(run_app)
+importFrom(dplyr,filter)
+importFrom(dplyr,left_join)
+importFrom(htmltools,HTML)
+importFrom(htmltools,a)
+importFrom(htmltools,tags)
+importFrom(leaflet,addLegend)
+importFrom(leaflet,addPolygons)
+importFrom(leaflet,addTiles)
+importFrom(leaflet,colorNumeric)
+importFrom(leaflet,highlightOptions)
+importFrom(leaflet,labelOptions)
+importFrom(leaflet,leaflet)
+importFrom(leaflet,leafletOutput)
+importFrom(sf,st_transform)
+importFrom(shiny,NS)
+importFrom(shiny,addResourcePath)
+importFrom(shiny,column)
+importFrom(shiny,fluidRow)
+importFrom(shiny,includeMarkdown)
+importFrom(shiny,moduleServer)
+importFrom(shiny,renderUI)
+importFrom(shiny,selectInput)
+importFrom(shiny,shinyApp)
+importFrom(shiny,uiOutput)
+importFrom(shinycssloaders,withSpinner)
+importFrom(shinydashboard,box)
+importFrom(shinydashboard,dashboardBody)
+importFrom(shinydashboard,dashboardHeader)
+importFrom(shinydashboard,dashboardPage)
+importFrom(shinydashboard,dashboardSidebar)
+importFrom(shinydashboard,menuItem)
+importFrom(shinydashboard,sidebarMenu)
+importFrom(shinydashboard,tabItem)
+importFrom(shinydashboard,tabItems)
+importFrom(tigris,counties)
+importFrom(utils,read.table)
diff --git a/R/get-county-boundaries.R b/R/get-county-boundaries.R
new file mode 100644
index 0000000..aed3965
--- /dev/null
+++ b/R/get-county-boundaries.R
@@ -0,0 +1,14 @@
+# Get the right county boundaries for the desired choropleth visualization
+#' @importFrom tigris counties
+#' @importFrom sf st_transform
+#'
+get_county_boundaries <- function(state_abbr, county_col_name) {
+ # Get county boundaries for the choropleth visualization using the tigris package
+ out <- sf::st_transform(
+ tigris::counties(state = state_abbr, class = "sf"),
+ crs = 4326
+ )
+
+ out[[county_col_name]] = out[['NAMELSAD']]
+ out
+}
diff --git a/R/global.R b/R/global.R
new file mode 100644
index 0000000..7bcb873
--- /dev/null
+++ b/R/global.R
@@ -0,0 +1 @@
+utils::globalVariables(c("NAMELSAD", "cancer_type", "race", "sex", "age", "stage", "year"))
diff --git a/R/make-leaflet.R b/R/make-leaflet.R
new file mode 100644
index 0000000..9540785
--- /dev/null
+++ b/R/make-leaflet.R
@@ -0,0 +1,41 @@
+# Make the choropleth map
+#' @importFrom leaflet leaflet addTiles addPolygons addLegend labelOptions
+#' highlightOptions
+#'
+make_leaflet <- function(in_data, in_palette, incidence_col_name,
+ county_col_name, legend_title) {
+
+ leaflet::leaflet(data = in_data) |>
+ leaflet::addTiles() |>
+ leaflet::addPolygons(
+ fillColor = ~in_palette(
+ in_data[[incidence_col_name]]
+ ),
+ weight = 1,
+ opacity = 1,
+ color = "white",
+ dashArray = "3",
+ fillOpacity = 0.7,
+ highlightOptions = leaflet::highlightOptions(
+ weight = 3,
+ color = "#666",
+ dashArray = "",
+ fillOpacity = 0.7,
+ bringToFront = TRUE
+ ),
+ label = ~paste(in_data[[county_col_name]], ": ",
+ in_data[[incidence_col_name]]),
+ labelOptions = leaflet::labelOptions(
+ style = list("font-weight" = "normal", padding = "3px 8px"),
+ textsize = "15px",
+ direction = "auto"
+ )
+ ) |>
+ leaflet::addLegend(
+ pal = in_palette,
+ values = ~in_data[[incidence_col_name]],
+ opacity = 0.7,
+ title = legend_title,
+ position = "topright"
+ )
+}
diff --git a/R/make-palette.R b/R/make-palette.R
new file mode 100644
index 0000000..610e7b2
--- /dev/null
+++ b/R/make-palette.R
@@ -0,0 +1,12 @@
+# Generate palette for choropleth map
+#' @importFrom leaflet colorNumeric
+#'
+make_palette <- function(in_data, col_name, lower_color, upper_color,
+ na_color) {
+
+ leaflet::colorNumeric(
+ c(lower_color, upper_color),
+ domain = in_data[[col_name]],
+ na.color = na_color
+ )
+}
diff --git a/R/oncarto-body.R b/R/oncarto-body.R
new file mode 100644
index 0000000..5a27ee1
--- /dev/null
+++ b/R/oncarto-body.R
@@ -0,0 +1,6 @@
+# This function fills in the body of the shiny dashboard
+#' @importFrom shinydashboard dashboardBody
+#'
+oncarto_body <- function() {
+
+}
diff --git a/R/oncarto-header.R b/R/oncarto-header.R
new file mode 100644
index 0000000..cd04fd0
--- /dev/null
+++ b/R/oncarto-header.R
@@ -0,0 +1,14 @@
+# This function fills in the header of the shiny dashboard
+#' @importFrom shinydashboard dashboardHeader
+#' @importFrom htmltools tags
+#'
+oncarto_header <- function(title, logo_src, logo_href, logo_width, logo_height) {
+ shinydashboard::dashboardHeader(
+ title = htmltools::tags$a(
+ href = logo_href,
+ tags$img(
+ src = logo_src, height = logo_height, width = logo_width
+ )
+ )
+ )
+}
diff --git a/R/oncarto-sidebar.R b/R/oncarto-sidebar.R
new file mode 100644
index 0000000..030affe
--- /dev/null
+++ b/R/oncarto-sidebar.R
@@ -0,0 +1,19 @@
+# This function fills in the sidebar of the shiny dashboard
+#' @importFrom shinydashboard dashboardSidebar sidebarMenu menuItem
+#'
+oncarto_sidebar <- function() {
+ shinydashboard::dashboardSidebar(
+ shinydashboard::sidebarMenu(
+ # Multiple tabs, each correspond to a different type of map / info
+ shinydashboard::menuItem(
+ "Cancer Incidence by County",
+ tabName = "county-incidence"
+ ),
+
+ shinydashboard::menuItem(
+ "Background",
+ tabName = "background"
+ )
+ )
+ )
+}
diff --git a/R/run-app.R b/R/run-app.R
new file mode 100644
index 0000000..cddb0b2
--- /dev/null
+++ b/R/run-app.R
@@ -0,0 +1,52 @@
+#' This function runs the Shiny app packaged within this R package.
+#' @param title Title of the application
+#' @param logo_src PNG or JPEG for the logo
+#' @param logo_href Website link for the logo
+#' @param logo_width Width of logo in pixels
+#' @param logo_height Height of logo in pixels
+#' @param css Filepath to the .css file that sets aesthetics for the whole app
+#' @param contact_info Filepath to a markdown file that includes contact
+#' information to be displayed at the bottom of the page
+#' @param callback A callback that returns a function that returns the relevant
+#' data
+#' @importFrom shiny shinyApp addResourcePath
+#' @importFrom shinydashboard dashboardPage dashboardBody tabItems
+#' @export
+#'
+
+run_app <- function(title, logo_src, logo_href, logo_width, logo_height, css,
+ contact_info, callback) {
+
+ shiny::addResourcePath(prefix = "img", directoryPath = dirname(logo_src))
+ logo_src <- file.path("img", basename(logo_src))
+
+ shiny::shinyApp(
+
+ ui = shinydashboard::dashboardPage(
+ oncarto_header(title, logo_src, logo_href, logo_width, logo_height),
+ oncarto_sidebar(),
+ shinydashboard::dashboardBody( # maybe replace with a new oncarto_body()?
+ shiny::includeCSS(css),
+ set_title(title),
+ shinydashboard::tabItems(
+ ui_county_incidence("incidence", contact_info),
+ ui_background("background")
+ )
+ )
+ ),
+
+ server = function(input, output, session) {
+ # WA County Incidence
+ server_county_incidence("incidence", callback, "WA",
+ "Age_Adjusted_Incidence_Rate", "County")
+
+ # Background Information
+ server_background("background")
+ }
+
+ )
+}
+
+
+
+
diff --git a/R/server-background.R b/R/server-background.R
new file mode 100644
index 0000000..856272e
--- /dev/null
+++ b/R/server-background.R
@@ -0,0 +1,7 @@
+# This function specifies the server logic for the background tab of the app.
+#' @importFrom shiny renderUI moduleServer
+#'
+server_background <- function(id) {
+ moduleServer(id, function(input, output, session){
+ })
+}
diff --git a/R/server-county-incidence.R b/R/server-county-incidence.R
new file mode 100644
index 0000000..b4d06e4
--- /dev/null
+++ b/R/server-county-incidence.R
@@ -0,0 +1,68 @@
+# This function specifies the server logic for the county incidence tab of the
+# app.
+#
+#' @importFrom shiny renderUI moduleServer
+#' @importFrom dplyr filter left_join
+#'
+server_county_incidence <- function(id, callback, state_abbr,
+ incidence_col_name, county_col_name) {
+
+ shiny::moduleServer(id, function(input, output, session) {
+ # Warning message if map can't be shown
+ warning_message <- "
No cancer incidence data are available for this specific combination of inputs. Please try a different combination of inputs.
"
+
+ # Get the shape file that includes county boundaries for the given US state
+ county_boundaries <- get_county_boundaries(state_abbr, county_col_name)
+
+ # Get input cancer incidence data based on the user-provided 'get_data' fn
+ # and table name
+ #fn_to_get_data <- get(func_to_apply)
+ #input_data <- fn_to_get_data(data_table_name)
+
+ input_data <- callback()
+
+ # Filter the incidence data by the input parameters
+ county_level_incidence <- shiny::reactive({
+ input_data |>
+ dplyr::filter(cancer_type == input$cancer_type, race == input$race,
+ sex == input$sex, age == input$age, stage == input$stage,
+ year == input$year)
+ })
+
+
+ # Determine if there is county-level incidence data to visualize
+ filters_too_strict <- shiny::eventReactive(county_level_incidence(), {
+ return(all(is.na(county_level_incidence()[[incidence_col_name]])))
+ })
+
+ shiny::observeEvent(filters_too_strict(),{
+ # If data do not exist for this combination of inputs, print a warning and
+ # return NULL instead of a map
+ if (isTRUE(filters_too_strict())) {
+ output$choropleth <- NULL
+ output$map_message <- renderUI({HTML(warning_message)})
+ }
+
+ # Otherwise, do not print a warning, and return the map
+ else {
+ # Set warning message to NULL
+ output$map_message <- NULL
+ output$choropleth <- leaflet::renderLeaflet({
+ # Join the cancer data with counties boundaries based on county name
+ county_level_incidence_with_shape <- county_boundaries |>
+ dplyr::left_join(county_level_incidence(), by = county_col_name)
+
+ # Generate color palette based on the selected cancer data
+ pal <- make_palette(county_level_incidence_with_shape,
+ incidence_col_name, "#F4F4F4", "#FFB500",
+ "transparent")
+
+ # Make the leaflet map
+ make_leaflet(county_level_incidence_with_shape, pal, incidence_col_name,
+ county_col_name, "Age-Adjusted Incidence Rate")
+ })
+ }
+ }
+ )
+ })
+}
diff --git a/R/set-title.R b/R/set-title.R
new file mode 100644
index 0000000..428da61
--- /dev/null
+++ b/R/set-title.R
@@ -0,0 +1,15 @@
+# Specify app title from set-aesthetics.R
+# @param title Title of app
+#' @importFrom htmltools tags HTML
+#'
+set_title <- function(title){
+ htmltools::tags$script(
+ htmltools::HTML(
+ paste0(
+ '$(document).ready(function() { $("header").find("nav").append(\' ',
+ title,
+ ' \');})'
+ )
+ )
+ )
+}
diff --git a/R/sysdata.rda b/R/sysdata.rda
new file mode 100644
index 0000000..ca254ec
Binary files /dev/null and b/R/sysdata.rda differ
diff --git a/R/test-callback.R b/R/test-callback.R
new file mode 100644
index 0000000..daeb172
--- /dev/null
+++ b/R/test-callback.R
@@ -0,0 +1,12 @@
+# A function that provides sample data (a .tsv) for testing.
+#' @importFrom utils read.table
+
+test_callback <- function(file_name) {
+ function() {
+ utils::read.table(
+ header = TRUE,
+ system.file(file.path("test", file_name), package = "oncarto"),
+ sep = "\t"
+ )
+ }
+}
diff --git a/R/ui-background.R b/R/ui-background.R
new file mode 100644
index 0000000..4e43ebc
--- /dev/null
+++ b/R/ui-background.R
@@ -0,0 +1,20 @@
+# This function specifies the UI for the background tab of the app.
+#' @importFrom shinydashboard tabItem box
+#' @importFrom shiny fluidRow column
+#'
+ui_background <- function(id) {
+ background = "Oncarto (Oncology Cartographer) is an R package / Shiny dashboard developed by the Fred Hutch Data Science Lab for the automated integration and visualization of publicly available cancer incidence data for the Fred Hutch Cancer Center catchment area. We aim to develop a robust, open-source cartographic data visualization package from the ground up that can take the data made available by State Cancer Profiles and make it easily accessible by the public. TO BE EDITED FURTHER."
+
+ shinydashboard::tabItem(
+ tabName = "background",
+ shiny::fluidRow(
+ shiny::column(
+ 12,
+ shinydashboard::box(
+ width = 12,
+ HTML(paste(background))
+ )
+ )
+ )
+ )
+}
diff --git a/R/ui-county-incidence.R b/R/ui-county-incidence.R
new file mode 100644
index 0000000..7dcd3d5
--- /dev/null
+++ b/R/ui-county-incidence.R
@@ -0,0 +1,81 @@
+# This function specifies the UI for the county incidence tab of the app.
+#' @importFrom shinydashboard tabItem box
+#' @importFrom shiny fluidRow column selectInput NS uiOutput includeMarkdown
+#' @importFrom shinycssloaders withSpinner
+#' @importFrom leaflet leafletOutput
+#' @importFrom htmltools a
+#'
+ui_county_incidence <- function(id, contact_info) {
+ shinydashboard::tabItem(
+ tabName = "county-incidence",
+ shiny::fluidRow(
+ shiny::column(
+ 4,
+ shinydashboard::box(
+ width = 12,
+
+ shiny::selectInput(
+ shiny::NS(id, "cancer_type"),
+ "Select cancer subtype of interest:",
+ choices = cancer_types
+ ),
+
+ shiny::selectInput(
+ shiny::NS(id, "race"),
+ "Select population race/ethnicity:",
+ choices = races
+ ),
+
+ shiny::selectInput(
+ shiny::NS(id, "sex"),
+ "Select sex:",
+ choices = sexes
+ ),
+
+ shiny::selectInput(
+ shiny::NS(id, "age"),
+ "Select age range:",
+ choices = ages
+ ),
+
+ shiny::selectInput(
+ shiny::NS(id, "stage"),
+ "Select cancer stage:",
+ choices = stages
+ ),
+
+ shiny::selectInput(
+ shiny::NS(id, "year"),
+ "Select time span:",
+ choices = years
+ )
+ )
+ ),
+
+ shiny::column(
+ 8,
+ shinydashboard::box(
+ width = 12,
+ shiny::uiOutput(
+ shiny::NS(id, "map_message")
+ ),
+ shinycssloaders::withSpinner(
+ leaflet::leafletOutput(
+ shiny::NS(id, "choropleth")
+ )
+ )
+ )
+ )
+ ),
+
+ shiny::fluidRow(
+ shiny::column(
+ 12,
+ shinydashboard::box(
+ width = 12,
+ shiny::includeMarkdown(contact_info)
+ )
+ )
+ )
+ )
+}
diff --git a/data-raw/contact-information.R b/data-raw/contact-information.R
new file mode 100644
index 0000000..79465c3
--- /dev/null
+++ b/data-raw/contact-information.R
@@ -0,0 +1,8 @@
+## code to prepare `DATASET` dataset goes here
+
+organization <- tags$a("Fred Hutch Data Science Lab (DaSL)", href = "https://hutchdatascience.org")
+team <- tags$a("DaSL Translational Analytics", href = "https://hutchdatascience.org/tr-analytics/")
+team_email <- tags$a("analytics@fredhutch.org", href = "mailto:analytics@fredhutch.org")
+
+# usethis::use_data(organization, team, team_email, overwrite = TRUE,
+# internal = FALSE)
diff --git a/data-raw/incidence-choices.R b/data-raw/incidence-choices.R
new file mode 100644
index 0000000..9d4ecaf
--- /dev/null
+++ b/data-raw/incidence-choices.R
@@ -0,0 +1,66 @@
+## code to prepare `DATASET` dataset goes here
+
+cancer_types = c(
+ "All subtypes" = "all cancer sites",
+ "Bladder" = "bladder",
+ "Brain and other nervous system" = "brain & ons",
+ "Breast (female)" = "breast (female)",
+ "Breast (female in situ)" = "breast (female in situ)",
+ "Cervix" = "cervix",
+ "Childhood (ages <15, all subtypes)" = "childhood (ages <15, all sites)",
+ "Childhood (ages <20, all subtypes)" = "childhood (ages <20, all sites)",
+ "Colon and rectum" = "colon & rectum",
+ "Esophagus" = "esophagus",
+ "Kidney and renal pelvis" = "kidney & renal pelvis",
+ "Leukemia" = "leukemia",
+ "Liver and bile duct" = "liver & bile duct",
+ "Lung and bronchus" = "lung & bronchus",
+ "Melanoma of the skin" = "melanoma of the skin",
+ "Non-hodgkin lymphoma" = "non-hodgkin lymphoma",
+ "Oral cavity and pharynx" = "oral cavity & pharynx",
+ "Ovary" = "ovary",
+ "Pancreas" = "pancreas",
+ "Prostate" = "prostate",
+ "Stomach" = "stomach",
+ "Thyroid" = "thyroid",
+ "Uterus (corpus and not otherwise specified)" = "uterus (corpus & uterus, nos)"
+)
+
+races = c(
+ "All races/ethnicities (including Hispanic)" = "All Races (includes Hispanic)",
+ "White (non-Hispanic)",
+ "Black (non-Hispanic)",
+ "American Indian / Alaska Native (non-Hispanic)",
+ "Asian / Pacific Islander (non-Hispanic)",
+ "Hispanic (Any Race)"
+)
+
+sexes = c(
+ "Any sex" = "both sexes",
+ "Male" = "males",
+ "Female" = "females"
+)
+
+
+ages = c(
+ "All ages" = "all ages",
+ "Ages <50" = "ages <50",
+ "Ages 50+" = "ages 50+",
+ "Ages <65" = "ages <65",
+ "Ages 65+" = "ages 65+",
+ "Ages <15" = "ages <15",
+ "Ages <20" = "ages <20"
+)
+
+stages = c(
+ "All stages" = "all stages",
+ "Late stage (regional & distant)" = "late stage (regional & distant)"
+)
+
+years = c(
+ "Latest 5 year average" = "latest 5 year average"
+)
+
+usethis::use_data(cancer_types, races, sexes, ages, stages, years,
+ overwrite = TRUE, internal = TRUE)
+
diff --git a/R/app.R b/inst/app.R
similarity index 99%
rename from R/app.R
rename to inst/app.R
index e7e4b3f..7888d13 100644
--- a/R/app.R
+++ b/inst/app.R
@@ -28,7 +28,7 @@ library(shinycssloaders)
# User-provided parameters for app aesthetics
# Set aesthetics of app (logo and title)
#source("R/set-aesthetics.R")
-source("set-aesthetics.R")
+source("../../R/set-aesthetics.R")
set_aesthetics()
# Set CSS file path
#css_file_path = "R/www/hutch_theme.css"
@@ -55,6 +55,7 @@ get_incidence_data <- function() {
incidence_data <- get_incidence_data()
+## TODO: come back to this
# Get county boundaries for the choropleth visualization using the tigris package
wa_counties_sf <- st_transform(
tigris::counties(state = "WA", class = "sf"),
@@ -110,7 +111,6 @@ ui <- dashboardPage(
tabItem(
# County incidence tab
tabName = "county-incidence",
-
# Show choropleth map
fluidRow(
column(
diff --git a/inst/app/contact-info.md b/inst/app/contact-info.md
new file mode 100644
index 0000000..38ed296
--- /dev/null
+++ b/inst/app/contact-info.md
@@ -0,0 +1 @@
+This application was developed by the [Fred Hutch Data Science Lab (DaSL)](https://hutchdatascience.org) organization. For questions or feedback regarding this application, email [DaSL Translational Analytics](https://hutchdatascience.org/tr-analytics/) at [analytics@fredhutch.org](mailto:analytics@fredhutch.org").
diff --git a/R/www/fhLogo.png b/inst/app/fhLogo.png
similarity index 100%
rename from R/www/fhLogo.png
rename to inst/app/fhLogo.png
diff --git a/R/www/hutch_theme.css b/inst/app/hutch_theme.css
similarity index 100%
rename from R/www/hutch_theme.css
rename to inst/app/hutch_theme.css
diff --git a/inst/get-data.R b/inst/get-data.R
new file mode 100644
index 0000000..7926abd
--- /dev/null
+++ b/inst/get-data.R
@@ -0,0 +1,25 @@
+# A function that returns a dataframe according to the name
+# (a string) specified by the first argument
+# @importFrom DBI dbConnect dbDisconnect dbReadTable
+# @importFrom RPostgres Postgres
+#
+
+get_data <- function(name_of_table) {
+ function() {
+ db_connection <- DBI::dbConnect(
+ RPostgres::Postgres(),
+ host = Sys.getenv("DB_HOST"),
+ dbname = Sys.getenv("DB_NAME"),
+ user = Sys.getenv("DB_USER"),
+ password = Sys.getenv("DB_PASSWORD"),
+ port = Sys.getenv("DB_PORT")
+ )
+
+ on.exit(DBI::dbDisconnect(db_connection))
+
+ DBI::dbReadTable(
+ name = name_of_table,
+ conn = db_connection
+ )
+ }
+}
diff --git a/inst/helper_functions.R b/inst/helper_functions.R
new file mode 100644
index 0000000..2d61991
--- /dev/null
+++ b/inst/helper_functions.R
@@ -0,0 +1,265 @@
+#' get_incidence_db_name: Get the right name for the data file to be saved
+#'
+#' @description
+#' Based on the user-specified parameters of cancer, race, sex, age, stage, and
+#' year, return an appropriate name for the database file to be saved
+#'
+#' @param cancer The type of cancer (character)
+#' @param race The race of the population (character)
+#' @param sex The sex of the population (character)
+#' @param age The age group of the population (character)
+#' @param stage The stage of the cancer (character)
+#' @param year The desired timespan for the data (character)
+#'
+#' @return
+#' The name of the database file to be saved to duckdb for this combination of
+#' parameters
+#'
+#' @examples
+#' get_incidence_db_name(
+#' "all cancer sites",
+#' "All Races (includes Hispanic)",
+#' "both sexes",
+#' "all ages",
+#' "all stages",
+#' "latest 5 year average"
+#' )
+#'
+
+get_incidence_db_name <- function(cancer, race, sex, age, stage, year){
+ ## all cancer sites = all
+ ## bladder = bladder
+ ## brain & ons = brain
+ ## colon & rectum = colon
+ ## esophagus = esophagus
+ ## kidney & renal pelvis = kidney
+ ## leukemia = leukemia
+ ## liver & bile duct = liver
+ ## lung & bronchus = lung
+ ## melanoma of the skin = melanoma
+ ## non-hodgkin lymphoma = lymphoma
+ ## oral cavity & pharynx = oral
+ ## pancreas = pancreas
+ ## stomach = stomach
+ ## thyroid = thyroid
+ c_name = "allsites" # all cancer sites
+ if (cancer == "bladder" ||
+ cancer == "esophagus" ||
+ cancer == "pancreas" ||
+ cancer == "stomach" ||
+ cancer == "thyroid" ||
+ cancer == "leukemia") {
+ c_name = cancer
+ } else if (cancer == "brain & ons") {
+ c_name = "brain"
+ } else if (cancer == "colon & rectum") {
+ c_name = "colon"
+ } else if (cancer == "kidney & renal pelvis") {
+ c_name = "kidney"
+ } else if (cancer == "liver & bile duct") {
+ c_name = "liver"
+ } else if (cancer == "lung & bronchus") {
+ c_name = "lung"
+ } else if (cancer == "melanoma of the skin") {
+ c_name = "melanoma"
+ } else if (cancer == "non-hodgkin lymphoma") {
+ c_name = "lymphoma"
+ } else if (cancer == "oral cavity & pharynx") {
+ c_name = "oral"
+ }
+
+ ## All Races (includes Hispanic) = allraces
+ ## White (non-Hispanic) = white
+ ## Black (non-Hispanic) = black
+ ## American Indian / Alaska Native (non-Hispanic) = native
+ ## Asian / Pacific Islander (non-Hispanic) = asian
+ ## Hispanic (Any Race) = hisp
+ r_name = "allraces" # All Races (includes Hispanic)
+ if (race == "White (non-Hispanic)") {
+ r_name = "white"
+ } else if (race == "Black (non-Hispanic)") {
+ r_name = "black"
+ } else if (race == "American Indian / Alaska Native (non-Hispanic)") {
+ r_name = "native"
+ } else if (race == "Asian / Pacific Islander (non-Hispanic)") {
+ r_name = "asian"
+ } else if (race == "Hispanic (Any Race)") {
+ r_name = "hisp"
+ }
+
+ ## both sexes = both
+ ## males = male
+ ## females = female
+ sx_name = "bothsexes" # both sexes
+ if (sex == "males") {
+ sx_name = "male"
+ } else if (sex == "females") {
+ sx_name = "female"
+ }
+
+ ## all ages = all
+ ## ages <50 = <50
+ ## ages 50+ = 50+
+ ## ages <65 = <65
+ ## ages 65+ = 65+
+ ## ages <15 = 15
+ ## ages <20 = 20
+ a_name = "allages" # all ages
+ if (age == "ages <50") {
+ a_name = "<50"
+ } else if (age == "ages 50+") {
+ a_name = "50+"
+ } else if (age == "ages <65") {
+ a_name = "<65"
+ } else if (age == "ages 65+") {
+ a_name = "65+"
+ } else if (age == "ages <15") {
+ a_name = "15"
+ } else if (age == "ages <20") {
+ a_name = "20"
+ }
+
+ ## all stages = allstage
+ ## late stage (regional & distant) = latestage
+ st_name = "allstages" # all stages
+ if (stage == "late stage (regional & distant)") {
+ st_name = "latestage"
+ }
+
+ ## latest 5 year average = 5yr
+ ## latest single year (us by state) = 1yr
+ y_name = "5yr" # latest 5 year average
+ if (stage == "latest single year (us by state)") {
+ y_name = "1yr"
+ }
+
+ #out = paste0("usa_state_", c_name, "_", r_name, "_", sx_name, "_", a_name, "_", st_name, "_", y_name)
+ out = paste0("usa_state_", cancer, "_", race, "_", sex, "_", age, "_", stage, "_", year)
+ return(out)
+}
+
+
+
+#' get_incidence_df: Collect cancer incidence data by US state
+#'
+#' @description
+#' Based on the user-specified parameters of cancer, race, sex, age, stage, and
+#' year, collect cancer incidence data by US state
+#'
+#' @param cancer The type of cancer (character)
+#' @param race The race of the population (character)
+#' @param sex The sex of the population (character)
+#' @param age The age group of the population (character)
+#' @param stage The stage of the cancer (character)
+#' @param year The desired timespan for the data (character)
+#'
+#' @return
+#' The output cancer incidence dataframe to be saved to duckdb for this
+#' combination of parameters
+#'
+#' @examples
+#' get_incidence_df(
+#' "all cancer sites",
+#' "All Races (includes Hispanic)",
+#' "both sexes",
+#' "all ages",
+#' "all stages",
+#' "latest 5 year average"
+#' )
+#'
+#'
+
+get_incidence_df <- function(cancer, race, sex, age, stage, year){
+ out = as.data.frame(
+ cancerprof::incidence_cancer(
+ "USA", "state",
+ cancer,
+ race,
+ sex,
+ age,
+ stage,
+ year
+ )
+ )
+
+ return(out)
+}
+
+
+
+#' merge_all_incidence: Join cancer incidence data across cancer types by state
+#'
+#' @description
+#' Based on the user-specified parameters of race, sex, age, stage, and year,
+#' collect cancer incidence data for all desired cancer types by US state
+#'
+#' @param cancer_types A list of all desired cancer types (vector)
+#' @param race The race of the population (character)
+#' @param sex The sex of the population (character)
+#' @param age The age group of the population (character)
+#' @param stage The stage of the cancer (character)
+#' @param year The desired timespan for the data (character)
+#' @param con The duckdb database to be accessed
+#'
+#' @return
+#' The output cancer incidence dataframe to be saved to duckdb for this
+#' combination of parameters
+#'
+#' @examples
+#' merge_all_incidence(
+#' c("all cancer sites", "thyroid"),
+#' "All Races (includes Hispanic)",
+#' "both sexes",
+#' "all ages",
+#' "all stages",
+#' "latest 5 year average",
+#' dbConnect(duckdb::duckdb(), "cancer-incidence-usa-state.duckdb")
+#' )
+#'
+#'
+
+merge_all_incidence <- function(cancer_types, race, sex, age, stage, year, con){
+ # Get a list of relevant tables from the db related to the parameters of interest
+ relevant_tables = c()
+ # Iterate over each cancer type
+ for (cancer in cancer_types) {
+ # Figure out what the name of the table should be if it exists in the db
+ table_name = get_incidence_db_name(cancer, race, sex, age, stage, year)
+ # If the table exists in the db, add its name to our list
+ if (table_name %in% dbListTables(con)) {
+ relevant_tables = c(relevant_tables, table_name)
+ }
+ }
+
+ # Merge relevant tables from the db to get final output data for visualization
+ out = data.frame()
+ # Iterate over tables in our db related to our parameters of interest
+ for (tableName in relevant_tables) {
+ # Get the type of cancer from the table's name
+ cancerName = strsplit(tableName, "_")[[1]][3]
+ # If this is the first table we're adding to the output...
+ if (nrow(out) == 0) {
+ # Read in the data, change the variable named "Age_Adjusted_Incidence_Rate"
+ # to be the name of the cancer type, and select this new column as well as
+ # the "State" column
+ out = dbReadTable(con, tableName) %>%
+ rename(!!cancerName := Age_Adjusted_Incidence_Rate) %>%
+ select(State, !!cancerName)
+ }
+ # Otherwise, the output already has some information in it
+ else {
+ # Read in the data and join it to the existing output by State. Make sure
+ # to rename the Incidence Rate column to correspond to the cancer type
+ out <- out %>%
+ left_join(
+ dbReadTable(con, tableName) %>%
+ rename(!!cancerName := Age_Adjusted_Incidence_Rate) %>%
+ select(State, !!cancerName),
+ by = "State"
+ )
+ }
+ }
+
+ # Return cancer incidence by state and cancer type
+ return(out)
+}
diff --git a/R/incidenceByState.qmd b/inst/incidenceByState.qmd
similarity index 100%
rename from R/incidenceByState.qmd
rename to inst/incidenceByState.qmd
diff --git a/R/incidenceByWAHSA.qmd b/inst/incidenceByWAHSA.qmd
similarity index 96%
rename from R/incidenceByWAHSA.qmd
rename to inst/incidenceByWAHSA.qmd
index be32068..ac307d6 100644
--- a/R/incidenceByWAHSA.qmd
+++ b/inst/incidenceByWAHSA.qmd
@@ -6,7 +6,7 @@ editor: visual
```{r}
library(pak)
-pak("getwilds/cancerprof@dev")
+pak("getwilds/cancerprof@fix-incidence")
pak("duckdb")
pak("duckplyr")
pak("DBI")
@@ -194,6 +194,21 @@ cancer_types = c(
```
Test code
+
+```{r}
+cancerprof::incidence_cancer(
+ area = "wa",
+ areatype = "county",
+ cancer = "all cancer sites",
+ race = "black (non-hispanic)",
+ sex = "both sexes",
+ age = "ages 65+",
+ stage = "all stages",
+ year = "latest 5 year average"
+)
+```
+
+
```{r}
test_data = cancerprof::incidence_cancer(
"USA", "state",
diff --git a/R/ingest-scp.R b/inst/ingest-scp.R
similarity index 91%
rename from R/ingest-scp.R
rename to inst/ingest-scp.R
index cbca553..0073d6f 100644
--- a/R/ingest-scp.R
+++ b/inst/ingest-scp.R
@@ -251,14 +251,14 @@ write_to_db <- function(df, df_name) {
#' )
#'
-ingest_scp_incidence <- function(state, cancer_types, race_options, sex_options, age_options, stage_options, year_options) {
+ingest_scp_incidence <- function(out_name, state, cancer_types, race_options, sex_options, age_options, stage_options, year_options) {
all_inputs <- get_input_combinations(
cancer_types, race_options, sex_options, age_options, stage_options, year_options
)
write_to_db(
get_incidence_for_all_inputs(state, all_inputs),
- paste0(state, "_county_incidence")
+ out_name
)
}
@@ -326,5 +326,37 @@ year_options = c(
"latest 5 year average"
)
-# ingest_scp_incidence("wa", cancer_types, race_options, sex_options,
-# age_options, stage_options, year_options)
+################################
+# Define the options for cancer types that can be viewed in the app
+cancer_types = c(
+ "all cancer sites",
+ "breast (female)",
+ "childhood (ages <15, all sites)",
+ "prostate"
+)
+
+race_options = c(
+ "All Races (includes Hispanic)"
+)
+
+sex_options = c(
+ "both sexes",
+ "males",
+ "females"
+)
+
+age_options = c(
+ "all ages",
+ "ages <15"
+)
+
+stage_options = c(
+ "all stages"
+)
+
+year_options = c(
+ "latest 5 year average"
+)
+
+ingest_scp_incidence("sample_wa_county_incidence", "wa", cancer_types, race_options, sex_options,
+ age_options, stage_options, year_options)
diff --git a/inst/oncarto.R b/inst/oncarto.R
new file mode 100644
index 0000000..387066a
--- /dev/null
+++ b/inst/oncarto.R
@@ -0,0 +1,14 @@
+#' Run the Shiny app
+#'
+#' This function runs the Shiny app packaged within this R package.
+#' @export
+#'
+
+runApp <- function() {
+ appDir <- system.file("shinyApp", package = "oncarto")
+ if (appDir == "") {
+ stop("Could not find Shiny app directory. Try re-installing `oncarto`.", call. = FALSE)
+ }
+
+ shiny::runApp(appDir, display.mode = "normal")
+}
diff --git a/R/set-aesthetics.R b/inst/set-aesthetics.R
similarity index 100%
rename from R/set-aesthetics.R
rename to inst/set-aesthetics.R
diff --git a/inst/test/sample-data.tsv b/inst/test/sample-data.tsv
new file mode 100644
index 0000000..9c54ef0
--- /dev/null
+++ b/inst/test/sample-data.tsv
@@ -0,0 +1,157 @@
+"County" "Age_Adjusted_Incidence_Rate" "cancer_type" "race" "sex" "age" "stage" "year"
+"1" "Clallam County" 501.1 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"2" "Mason County" 492 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"3" "Grays Harbor County" 489.7 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"4" "Skagit County" 489.2 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"5" "Kitsap County" 486.3 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"6" "Pierce County" 482.1 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"7" "Snohomish County" 480.8 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"8" "Thurston County" 480.4 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"9" "Whatcom County" 475.8 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"10" "Jefferson County" 474.1 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"11" "Island County" 472.6 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"12" "Okanogan County" 468.3 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"13" "Douglas County" 468.1 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"14" "Chelan County" 465.3 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"15" "San Juan County" 444.6 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"16" "King County" 441.4 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"17" "Yakima County" 414.8 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"18" "Grant County" 412.8 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"19" "Benton County" 412 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"20" "Wahkiakum County" 400.1 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"21" "Franklin County" 399.4 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"22" "Pacific County" 397.7 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"23" "Lewis County" 394.6 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"24" "Kittitas County" 390.7 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"25" "Cowlitz County" 389.4 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"26" "Columbia County" 388.8 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"27" "Walla Walla County" 388.2 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"28" "Klickitat County" 387 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"29" "Clark County" 378.5 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"30" "Spokane County" 372 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"31" "Adams County" 359.4 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"32" "Lincoln County" 354.1 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"33" "Pend Oreille County" 350.5 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"34" "Garfield County" 349 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"35" "Stevens County" 343.7 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"36" "Skamania County" 340.5 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"37" "Asotin County" 324 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"38" "Ferry County" 298 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"39" "Whitman County" 262.9 "all cancer sites" "All Races (includes Hispanic)" "both sexes" "all ages" "all stages" "latest 5 year average"
+"40" "Jefferson County" 147.2 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"41" "Kitsap County" 138.3 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"42" "Whatcom County" 129.6 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"43" "Clallam County" 128.6 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"44" "Grays Harbor County" 125.2 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"45" "San Juan County" 122.7 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"46" "Chelan County" 122.5 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"47" "Mason County" 118.2 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"48" "Island County" 115.7 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"49" "King County" 114.4 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"50" "Thurston County" 113.8 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"51" "Walla Walla County" 113.4 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"52" "Pierce County" 112.7 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"53" "Kittitas County" 111.6 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"54" "Grant County" 110.1 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"55" "Skagit County" 109.7 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"56" "Snohomish County" 107.6 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"57" "Douglas County" 104 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"58" "Yakima County" 102.5 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"59" "Okanogan County" 102 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"60" "Adams County" 96.9 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"61" "Pacific County" 96.1 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"62" "Benton County" 96 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"63" "Franklin County" 89.9 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"64" "Klickitat County" 86.9 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"65" "Lewis County" 84.1 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"66" "Wahkiakum County" 80.1 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"67" "Columbia County" 79.8 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"68" "Lincoln County" 73 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"69" "Spokane County" 68.9 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"70" "Clark County" 64.3 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"71" "Asotin County" 58.8 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"72" "Cowlitz County" 58.2 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"73" "Skamania County" 52.8 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"74" "Pend Oreille County" 51.5 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"75" "Stevens County" 51.1 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"76" "Whitman County" 34.1 "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"77" "Ferry County" NA "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"78" "Garfield County" NA "prostate" "All Races (includes Hispanic)" "males" "all ages" "all stages" "latest 5 year average"
+"79" "San Juan County" 164.2 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"80" "Skagit County" 154.7 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"81" "Snohomish County" 149.5 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"82" "Lincoln County" 147.7 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"83" "King County" 146.5 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"84" "Whatcom County" 145.1 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"85" "Chelan County" 144.8 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"86" "Thurston County" 143.1 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"87" "Okanogan County" 141.7 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"88" "Wahkiakum County" 140.2 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"89" "Pierce County" 139.4 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"90" "Walla Walla County" 138 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"91" "Kitsap County" 136.6 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"92" "Spokane County" 134.1 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"93" "Island County" 134 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"94" "Clallam County" 132.5 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"95" "Benton County" 128.9 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"96" "Stevens County" 125.5 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"97" "Mason County" 123.7 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"98" "Klickitat County" 121.7 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"99" "Yakima County" 121.5 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"100" "Douglas County" 120 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"101" "Jefferson County" 119.3 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"102" "Grays Harbor County" 118.8 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"103" "Clark County" 117.8 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"104" "Pacific County" 116.1 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"105" "Adams County" 115.3 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"106" "Franklin County" 114.6 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"107" "Grant County" 114.1 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"108" "Whitman County" 114 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"109" "Columbia County" 112.8 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"110" "Lewis County" 112.3 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"111" "Pend Oreille County" 111.6 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"112" "Kittitas County" 97.4 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"113" "Cowlitz County" 97.2 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"114" "Skamania County" 90.9 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"115" "Ferry County" 87.3 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"116" "Asotin County" 66.9 "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"117" "Garfield County" NA "breast (female)" "All Races (includes Hispanic)" "females" "all ages" "all stages" "latest 5 year average"
+"118" "Lewis County" 27.5 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"119" "Thurston County" 21.6 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"120" "Clark County" 21.1 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"121" "Franklin County" 20.5 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"122" "Yakima County" 19.6 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"123" "King County" 18.1 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"124" "Snohomish County" 17.8 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"125" "Grant County" 17.7 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"126" "Pierce County" 17.5 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"127" "Whatcom County" 17 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"128" "Skagit County" 16.7 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"129" "Benton County" 16.6 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"130" "Spokane County" 15.4 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"131" "Kitsap County" 13.4 "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"132" "Adams County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"133" "Asotin County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"134" "Chelan County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"135" "Clallam County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"136" "Columbia County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"137" "Cowlitz County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"138" "Douglas County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"139" "Ferry County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"140" "Garfield County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"141" "Grays Harbor County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"142" "Island County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"143" "Jefferson County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"144" "Kittitas County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"145" "Klickitat County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"146" "Lincoln County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"147" "Mason County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"148" "Okanogan County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"149" "Pacific County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"150" "Pend Oreille County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"151" "San Juan County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"152" "Skamania County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"153" "Stevens County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"154" "Wahkiakum County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"155" "Walla Walla County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
+"156" "Whitman County" NA "childhood (ages <15, all sites)" "All Races (includes Hispanic)" "both sexes" "ages <15" "all stages" "latest 5 year average"
diff --git a/man/hello.Rd b/man/hello.Rd
deleted file mode 100644
index 0fa7c4b..0000000
--- a/man/hello.Rd
+++ /dev/null
@@ -1,12 +0,0 @@
-\name{hello}
-\alias{hello}
-\title{Hello, World!}
-\usage{
-hello()
-}
-\description{
-Prints 'Hello, world!'.
-}
-\examples{
-hello()
-}
diff --git a/man/run_app.Rd b/man/run_app.Rd
new file mode 100644
index 0000000..a4ad2f4
--- /dev/null
+++ b/man/run_app.Rd
@@ -0,0 +1,39 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/run-app.R
+\name{run_app}
+\alias{run_app}
+\title{This function runs the Shiny app packaged within this R package.}
+\usage{
+run_app(
+ title,
+ logo_src,
+ logo_href,
+ logo_width,
+ logo_height,
+ css,
+ contact_info,
+ callback
+)
+}
+\arguments{
+\item{title}{Title of the application}
+
+\item{logo_src}{PNG or JPEG for the logo}
+
+\item{logo_href}{Website link for the logo}
+
+\item{logo_width}{Width of logo in pixels}
+
+\item{logo_height}{Height of logo in pixels}
+
+\item{css}{Filepath to the .css file that sets aesthetics for the whole app}
+
+\item{contact_info}{Filepath to a markdown file that includes contact
+information to be displayed at the bottom of the page}
+
+\item{callback}{A callback that returns a function that returns the relevant
+data}
+}
+\description{
+This function runs the Shiny app packaged within this R package.
+}
diff --git a/tests/testthat.R b/tests/testthat.R
new file mode 100644
index 0000000..cb6035e
--- /dev/null
+++ b/tests/testthat.R
@@ -0,0 +1,12 @@
+# This file is part of the standard setup for testthat.
+# It is recommended that you do not modify it.
+#
+# Where should you do additional test configuration?
+# Learn more about the roles of various files in:
+# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
+# * https://testthat.r-lib.org/articles/special-files.html
+
+library(testthat)
+library(oncarto)
+
+test_check("oncarto")
diff --git a/tests/testthat/test-server-county-incidence.R b/tests/testthat/test-server-county-incidence.R
new file mode 100644
index 0000000..f8c1e33
--- /dev/null
+++ b/tests/testthat/test-server-county-incidence.R
@@ -0,0 +1,124 @@
+# This function specifies the server logic for the county incidence tab of the
+# app.
+
+# Test that map shows up with baseline inputs
+test_that("Baseline input works", {
+ shiny::testServer(
+ server_county_incidence,
+ args = list(id = "incidence", test_callback("sample-data.tsv"),
+ "WA", "Age_Adjusted_Incidence_Rate", "County"), {
+
+ session$setInputs(
+ cancer_type = oncarto:::cancer_types[1],
+ race = oncarto:::races[1],
+ sex = oncarto:::sexes[1],
+ age = oncarto:::ages[1],
+ stage = oncarto:::stages[1],
+ year = oncarto:::years[1]
+ )
+
+ # Check that a map is generated
+ expect_true(!is.null(output$choropleth))
+ })
+})
+
+
+
+
+# Test that map shows up with female-specific cancer
+test_that("Female-specific cancer works", {
+ shiny::testServer(
+ server_county_incidence,
+ args = list(id = "incidence", test_callback("sample-data.tsv"),
+ "WA", "Age_Adjusted_Incidence_Rate", "County"), {
+
+ session$setInputs(
+ cancer_type = "breast (female)",
+ race = oncarto:::races[1],
+ sex = oncarto:::sexes[1],
+ age = oncarto:::ages[1],
+ stage = oncarto:::stages[1],
+ year = oncarto:::years[1]
+ )
+
+ expect_true(!is.null(output$map_message))
+
+ session$setInputs(
+ cancer_type = "breast (female)",
+ race = oncarto:::races[1],
+ sex = "females",
+ age = oncarto:::ages[1],
+ stage = oncarto:::stages[1],
+ year = oncarto:::years[1]
+ )
+
+ # Check that a map is generated
+ expect_true(!is.null(output$choropleth))
+ })
+})
+
+
+# Test that map shows up with male-specific cancer
+test_that("Male-specific cancer works", {
+ shiny::testServer(
+ server_county_incidence,
+ args = list(id = "incidence", test_callback("sample-data.tsv"),
+ "WA", "Age_Adjusted_Incidence_Rate", "County"), {
+
+ session$setInputs(
+ cancer_type = "prostate",
+ race = oncarto:::races[1],
+ sex = oncarto:::sexes[1],
+ age = oncarto:::ages[1],
+ stage = oncarto:::stages[1],
+ year = oncarto:::years[1]
+ )
+
+ expect_true(!is.null(output$map_message))
+
+ session$setInputs(
+ cancer_type = "prostate",
+ race = oncarto:::races[1],
+ sex = "males",
+ age = oncarto:::ages[1],
+ stage = oncarto:::stages[1],
+ year = oncarto:::years[1]
+ )
+
+ # Check that a map is generated
+ expect_true(!is.null(output$choropleth))
+ })
+})
+
+# Test that map shows up with age-specific cancer
+test_that("Age-specific cancer works", {
+ shiny::testServer(
+ server_county_incidence,
+ args = list(id = "incidence", test_callback("sample-data.tsv"),
+ "WA", "Age_Adjusted_Incidence_Rate", "County"), {
+
+ session$setInputs(
+ cancer_type = "childhood (ages <15, all sites)",
+ race = oncarto:::races[1],
+ sex = oncarto:::sexes[1],
+ age = oncarto:::ages[1],
+ stage = oncarto:::stages[1],
+ year = oncarto:::years[1]
+ )
+
+ expect_true(!is.null(output$map_message))
+
+ session$setInputs(
+ cancer_type = "childhood (ages <15, all sites)",
+ race = oncarto:::races[1],
+ sex = oncarto:::sexes[1],
+ age = "ages <15",
+ stage = oncarto:::stages[1],
+ year = oncarto:::years[1]
+ )
+
+ # Check that a map is generated and that the output map message is NULL
+ expect_true(!is.null(output$choropleth))
+ })
+})
+