Skip to content

Commit

Permalink
generalized dataInfo module
Browse files Browse the repository at this point in the history
Uses the `moduleName/moduleName_data.Rmd` file (if present) that documents the module's data, and renders it in the UI
  • Loading branch information
achubaty committed Feb 14, 2018
1 parent b99e93c commit 7fb05ae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 55 deletions.
68 changes: 16 additions & 52 deletions R/simInfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,28 @@ moduleInfoUI <- function(id) {
#' @param input shiny server input object
#' @param output shiny server output object
#' @param session shiny server session object
#' @param sim A \code{simList} object
#' @param sim A \code{simList} object.
#' @param data Logical. \code{TRUE} indicates to use the Rmd file for the
#' module's data (\file{moduleName/moduleName_data.Rmd}), if present.
#' \code{FALSE} uses the module's Rmd file (\file{moduleName/moduleName.Rmd}).
#'
#' @export
#' @importFrom shiny actionLink div fluidRow includeMarkdown p renderUI tagList
#' @importFrom shinyBS bsModal
#' @importFrom shinydashboard box
#' @importFrom SpaDES.core depends modulePath
#' @importFrom SpaDES.core depends modulePath modules
#' @rdname moduleInfo
moduleInfo <- function(input, output, session, sim) {
moduleInfo <- function(input, output, session, sim, data = FALSE) {
output$allModuleInfo <- renderUI({
fluidRow(
tagList(lapply(modules(sim), function(module) {
m <- slot(depends(sim), "dependencies")[[module]]
rmdFile <- file.path(modulePath(sim), module, paste0(module, ".Rmd"))
rmdFileName <- if (data) {
paste0(module, "_data.Rmd")
} else {
paste0(module, ".Rmd")
}
rmdFile <- file.path(modulePath(sim), module, rmdFileName)
box(title = module, width = 12, status = "success", collapsible = TRUE,
div(
p(paste("Description:", slot(m, "description"))),
Expand Down Expand Up @@ -267,7 +275,8 @@ moduleParams <- function(input, output, session, sim) {

#' Module data sources information module
#'
#' TO DO: needs to be generalized
#' Display the rendered Rmarkdown content of the module's data description file
#' (\file{moduleName/moduleName_data.Rmd}).
#'
#' @param id An ID string that corresponds with the ID used to call the module's
#' UI function
Expand All @@ -280,52 +289,7 @@ moduleParams <- function(input, output, session, sim) {
dataInfoUI <- function(id) {
ns <- NS(id)

fluidRow(
box(title = "Climate Suitability", width = 12, status = "success",
collapsible = TRUE, collapsed = TRUE,
h4("Summary"),
p("This module imports several MPB climate suitability scenarios (using four different indices: `S`, `L`, `R`, `G`) for use as model drivers.",
"The Logan suitability index (`L`) is based on summer temperatures (Logan et al. 2003).",
"The Regniere suitability index (`R`) is based on MPB cold tolerance (i.e., winter survival) (Regniere et al. 2007).",
"The Safranyik suitability index (`S`) is based on aspects of both summer temperatures and winter survival (Safranyik et al. 1975).",
"Finally, the composite SLR index (`G`) takes the geometric mean of the `S`, `L`, and `R` models.",
"These are described in further detail in Nealis et al. (2008 and 2014) and in their respective publications cited above."),
p("BioSim was used to generate the maps (see Bentz et al. 2010; Logan et al. 2003; Safranyik et al. 2010)."),

h4("References"),
p("Bentz, B J, J R\u00e9gni\u00e8re, C J Fettig, E M Hansen, J L Hayes, J A Hicke, R. G. Kelsey, J. F. Negr\u00f3n, and S. J. Seybold. 2010. \"Climate Change and Bark Beetles of the Western United States and Canada: Direct and Indirect Effects.\" BioScience 60(8):602-13. doi:10.1525/bio.2010.60.8.6."),
p("Logan, Jesse A, Jacques R\u00e9gni\u00e8re, and James A Powell. 2003. \"Assessing the impacts of global warming on forest pest dynamics.\" Frontiers in Ecology and the Environment 1(3):130-37. doi:10.1890/1540-9295(2003)001[0130:ATIOGW]2.0.CO;2."),
p("Nealis, Vince G, and Barry J Cooke. 2014. \"Risk assessment of the threat of mountain pine beetle to Canada's boreal and eastern pine forests.\" Ottawa, ON: Canadian Council of Forest Ministers. http://cfs.nrcan.gc.ca/publications?id=35406."),
p("Nealis, Vince G, and Brian Peter. 2008. \"Risk assessment of the threat of mountain pine beetle to Canada's boreal and eastern pine forests.\" Infromation Report. Victoria, BC: Natural Resources Canada, Canadian Forest Service, Pacific Forestry Centre."),
p("R\u00e9gni\u00e8re, Jacques, and Barbara Bentz. 2007. \"Modeling cold tolerance in the mountain pine beetle, Dendroctonus ponderosae.\" Journal of Insect Physiology 53(6): 559-72. doi:10.1016/j.jinsphys.2007.02.007."),
p("Safranyik, Les, Allan L Carroll, Jacques R\u00e9gni\u00e8re, David W Langor, William G Riel, Terry L Shore, Brian Peter, Barry J Cooke, Vince G Nealis, and Stephen W Taylor. 2010. \"Potential for range expansion of mountain pine beetle into the boreal forest of North America.\" The Canadian Entomologist 142(5):415-42. doi:10.4039/n08-CPA01."),
p("Safranyik, L.; Shrimpton, D.M.; Whitney, H.S. 1975. \"An interpretation of the interaction between lodgepole pine, the mountain pine beetle, and its associated blue stain fungi in western Canada.\" In Management of Lodgepole Pine Ecosystems Symposium Proceedings, edited by D M Baumgartner, 406-28. Pullman, WA: Washington State University Coop. Extension Service. http://wfiwc.org/sites/default/files/Safranyik_Shrimpton_Whitney_1975.pdf.")
),
box(title = "Mountain Pine Beetle Attack", width = 12, status = "success",
collapsible = TRUE, collapsed = TRUE,
h4("Summary"),
p("MPB aerial survey data for BC and AB are provided by those provinces as point and polygon data."),
p("Cooke & Carroll (in press) describes the methodology by which MPB attack data for AB (derived from spatial points) and BC (derived from polygons) have been rasterized and merged into a single `RasterLayer`:"),
tags$blockquote("To provide an unbiased perspective on MPB damage in the two provinces, the two data sets were rasterized to a common resolution, allowing impact to be expressed in common units (hectares attacked per 4 km2 cell).",
"For BC data, raster cells were weighted according to polygon-wide average infestation rates and areas calculated from the proportion of a polygon infested within each raster cell, assuming an average stem density of 1125 mature stems per hectare, which is typical for beetle-prone lodgepole pine stands (Whitehead and Russo, 2005).",
"Data were weighted and calculated for each year in the sequence, and then summed. For Alberta data, the number of attacked trees per point attack cluster was determined from provincial government records, based on a ground survey, and summed across years within each 4 km2 raster cell."),
p("NOTE: We produced finer-resolusion rasters (250m x 250m) to match the resolution of the kNN pine maps."),
p("NOTE: currently, only the data up to and including 2011 are being used, as more recent data for BC have not yet been acquired (we have AB aerial survey data up to and including 2016)."),

h4("References"),
p("Cooke, Barry J, and Allan L Carroll. in press. \"The risk of mountain pine beetle spread to eastern pine forests: what can we predict?\""),
p("Whitehead, R J, Russo, G L. 2005. \"\'Beetle-proofed\' lodgepole pine stands in interior British Columbia have less damage from mountain pine beetle\". Info. Rep. No. BC-X-402. Natural Resources Canada, Canadian Forest Service, Pacific Forestry Centre, Victoria, B.C.")
),
box(title = "Pine Availability", width = 12, status = "success",
collapsible = TRUE, collapsed = TRUE,
h4("Summary"),
p("Beaudoin et al. (2014) produced estimates of percent cover for several major tree species across Canada, including lodgepole pine and jack pine, at 250m resolution.",
"These estimates are used to provide a base map of the proportion pine available to MPB in each pixel."),

h4("References"),
p("Beaudoin, A, P Y Bernier, L Guindon, P Villemaire, X J Guo, G Stinson, T Bergeron, S Magnussen, and R J Hall. 2014. \"Mapping attributes of Canada's forests at moderate resolution through kNN and MODIS imagery.\" Canadian Journal of Forest Research 44: 521-32. doi:10.1139/cjfr-2013-0401.")
)
)
moduleInfoUI(ns("allDataInfo"))
}

#' @param input shiny server input object
Expand All @@ -336,5 +300,5 @@ dataInfoUI <- function(id) {
#' @export
#' @rdname dataInfo
dataInfo <- function(input, output, session, sim) {
##
callModule(moduleInfo, "allDataInfo", sim, data = TRUE)
}
3 changes: 2 additions & 1 deletion man/dataInfo.Rd

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

8 changes: 6 additions & 2 deletions man/moduleInfo.Rd

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

1 comment on commit 7fb05ae

@lintr-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R/simOutputs.R:92:6: style: Commented code should be removed.

#Plot(demoArea, addTo = "map") ## TO DO: use studyArea from inside simList
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Please sign in to comment.