From 62be5b738d43c0d2538f9dde0cae906df726da78 Mon Sep 17 00:00:00 2001 From: Martin Jung Date: Thu, 21 Mar 2024 17:08:40 +0100 Subject: [PATCH] Starting to add the Glossary to the protocol --- R/app_server.R | 2 ++ R/app_ui.R | 6 ++++ R/mod_Design.R | 7 +++-- R/mod_Glossary.R | 67 +++++++++++++++++++++++++++++++++++++++++ R/mod_Prioritization.R | 7 +++-- R/mod_Specification.R | 36 +++++++++++++++------- dev/02_dev.R | 3 +- inst/01_protocol.yaml | 15 ++++++--- inst/glossary_table.csv | 14 +++++++++ 9 files changed, 135 insertions(+), 22 deletions(-) create mode 100644 R/mod_Glossary.R create mode 100644 inst/glossary_table.csv diff --git a/R/app_server.R b/R/app_server.R index 26fb602..b0591c4 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -94,11 +94,13 @@ app_server <- function(input, output, session) { # News mod_News_server("News_1") + mod_Glossary_server("Glossary_1") # Import/Export mod_Import_server("Import_1") mod_Export_server("Export_1", results) # Automatically stop a Shiny app when closing the browser tab + # NOTE: Disabled this as it seems to stop the instance across browsers # session$onSessionEnded(stopApp) } diff --git a/R/app_ui.R b/R/app_ui.R index 679a02a..fe6433b 100644 --- a/R/app_ui.R +++ b/R/app_ui.R @@ -123,6 +123,11 @@ app_ui <- function(request) { tabName = "News", icon = shiny::icon("newspaper") ), + bs4Dash::menuItem( + "Glossary", + tabName = "Glossary", + icon = shiny::icon("book") + ), bs4Dash::menuItem( "Issues and Feedback", href = "https://github.com/iiasa/ODPSCP/issues", @@ -151,6 +156,7 @@ app_ui <- function(request) { mod_Prioritization_ui("Prioritization_1"), # News mod_News_ui("News_1"), + mod_Glossary_ui("Glossary_1"), # Import mod_Import_ui("Import_1"), mod_Export_ui("Export_1") diff --git a/R/mod_Design.R b/R/mod_Design.R index 394cd4e..f6b1a82 100644 --- a/R/mod_Design.R +++ b/R/mod_Design.R @@ -99,9 +99,10 @@ mod_Design_ui <- function(id){ solidHeader = TRUE, status = "secondary", collapsible = FALSE, - shiny::p('Most SCP applications are applied rather than curiosity driven. - Here we ask whether the pathway to impact and - influencing outcomes is clear.'), + shiny::p('Most SCP applications are applied rather than curiosity driven. However an applied + focus does not necessarily mean that the work will be implemented and the pathway to + impact is clear. A theory of change is a apriori process that maps the relationship between + a long-term goal of a planning objective and the necessary steps required to implement it.'), shiny::textAreaInput(inputId = ns("theoryofchange"), label = "", placeholder = 'Describe the theory of change if there is any.', height = "45px", width = "100%", resize = "vertical") diff --git a/R/mod_Glossary.R b/R/mod_Glossary.R new file mode 100644 index 0000000..e1f30a1 --- /dev/null +++ b/R/mod_Glossary.R @@ -0,0 +1,67 @@ +#' Glossary UI Function +#' +#' @description A shiny Module. +#' +#' @param id,input,output,session Internal parameters for {shiny}. +#' +#' @noRd +#' +#' @importFrom shiny NS tagList +#' @importFrom bs4Dash insertTab tabItem tabItems +#' @importFrom shiny actionButton tabsetPanel column +mod_Glossary_ui <- function(id){ + ns <- NS(id) + + bs4Dash::tabItem( + tabName = "Glossary", + shiny::fluidPage( + shiny::fluidRow( + shiny::column(width = 2), + shiny::column(width = 12, + bs4Dash::tabsetPanel( + id = ns("Glossary"), + type = "pills", + vertical = FALSE, + selected = "Glossary", + # News panel + shiny::tabPanel( + title = "Glossary", + shiny::br(), + bs4Dash::box( + title = "Glossary", + status = "primary", + solidHeader = TRUE, + collapsed = FALSE, + width = 12, + DT::dataTableOutput('glossary_table') + ) + ) + ) + ) + ) + ) # End fluidpage + ) # End of tabItem +} + +#' Glossary Server Functions +#' +#' @noRd +mod_Glossary_server <- function(id){ + shiny::moduleServer( id, function(input, output, session){ + ns <- session$ns + + # Get the protocol for print + ppath <- system.file("glossary_table.csv", + package = "ODPSCP", + mustWork = TRUE) + output$glossary_table <- DT::renderDataTable( + read.csv(ppath) + ) + }) +} + +## To be copied in the UI +# mod_Glossary_ui("Glossary_1") + +## To be copied in the server +# mod_Glossary_server("Glossary_1") diff --git a/R/mod_Prioritization.R b/R/mod_Prioritization.R index bb39a9d..dd1729c 100644 --- a/R/mod_Prioritization.R +++ b/R/mod_Prioritization.R @@ -53,7 +53,7 @@ mod_Prioritization_ui <- function(id){ label = "Used software", choices = c("","Zonation","Marxan", "prioritizr","prioriactions", - "RestOptr","oppr", + "RestOptr","oppr", "ConsNet", "CAPTAIN","ROOT", "C-PLAN", "Custom","Other"), options = list( @@ -75,8 +75,9 @@ mod_Prioritization_ui <- function(id){ ns = ns, shiny::p("Enter a version number of the used software. Also provide any other information related to software - (for example if a specific solver was used for integer programming)."), - shiny::textAreaInput(inputId = ns("versionnr"), label = "Provide a version number and other information related to software.", + (for example if a specific solver was used for mathematical programming such as Gurobi or Symphony)."), + shiny::textAreaInput(inputId = ns("versionnr"), + label = "Provide a version number and other information related to the software.", placeholder = 'Enter free text here.', height = "45px", width = "100%", resize = "none") ), diff --git a/R/mod_Specification.R b/R/mod_Specification.R index 74c8153..218a14c 100644 --- a/R/mod_Specification.R +++ b/R/mod_Specification.R @@ -99,25 +99,39 @@ mod_Specification_ui <- function(id){ ), shiny::br(), bs4Dash::box( - title = "Planning unit costs", + title = "Planning unit costs or penalities", closable = FALSE, width = 12, solidHeader = TRUE, status = "secondary", collapsible = FALSE, + shiny::p("The decision where to allocate conservation efforts can to a large degree be determined + by economic, biophysical or socio-economic constraints. One way of including those in planning + studies is to threat them as a cost or penality, thus penalizing the selection of any outcomes + with too high costs. Typical are for example the costs of land acquistion in area-based planning."), shinyWidgets::pickerInput( inputId = ns("pu_checkcosts"), - label = "Where there any costs of selecting a planning unit?", - choices = c("No", "Area only", "Yes"), - multiple = FALSE + label = "Where there any costs or penalities for selecting a planning unit? Select one or multiple.", + choices = c( + c("Area only", + "Biophysical proxy", + "Socioeconomic proxy", + "Implementation cost", + "Acquisition cost", + "Opportunity cost", + "Management cost", + "Logistics cost", + "Sampling effort", + "Other") + ), + options = list(`actions-box` = TRUE), + multiple = TRUE ), - shiny::conditionalPanel( - condition = "input.pu_checkcosts == 'Yes'", - ns = ns, - shiny::textAreaInput(inputId = ns("pu_costs"), label = "Describe process of creating costs", - placeholder = 'Provide some detail on how costs were defined or created.', - height = "45px", width = "100%", resize = "none") - ) + shiny::br(), + # Any other cost description? + shiny::textAreaInput(inputId = ns("pu_costs"), label = "Describe process of creating costs", + placeholder = 'Provide some detail on how costs were defined or created.', + height = "45px", width = "100%", resize = "none") ) ) ) # End column diff --git a/dev/02_dev.R b/dev/02_dev.R index d63f9d3..fa51465 100644 --- a/dev/02_dev.R +++ b/dev/02_dev.R @@ -28,6 +28,7 @@ golem::add_module(name = "Context", with_test = FALSE) # Name of the module golem::add_module(name = "Planning", with_test = FALSE) # Name of the module golem::add_module(name = "News", with_test = FALSE) # Name of the module +golem::add_module(name = "Glossary", with_test = FALSE) # Name of the module golem::add_module(name = "Import", with_test = FALSE) # Name of the module golem::add_module(name = "Export", with_test = FALSE) # Name of the module @@ -47,7 +48,7 @@ golem::add_utils("format_protocol", with_test = FALSE) # Text external ## Add internal datasets ---- ## If you have data in your package -# usethis::use_data_raw(name = "my_dataset", open = FALSE) +# usethis::use_data_raw(name = "glossary_table", open = FALSE) ## Tests ---- ## Add one line by test you want to create diff --git a/inst/01_protocol.yaml b/inst/01_protocol.yaml index b5efeac..c3bb513 100644 --- a/inst/01_protocol.yaml +++ b/inst/01_protocol.yaml @@ -315,13 +315,20 @@ specification: render-nr: 3 render-id: 'pu_checkcosts' render-group: 'planningunits' - question: 'Was the decision of selecting planning units driven by some costs?' + question: 'Where there any costs of selecting a planning unit? Select one or multiple.' description: 'Describe the grain of planning units if applicable.' - fieldtype: 'dropdown' + fieldtype: 'multiplechoice' options: - - None - Area only - - Yes + - Biophysical proxy + - Socioeconomic proxy + - Implementation cost + - Acquisition cost + - Opportunity cost + - Management cost + - Logistics cost + - Sampling effort + - Other fieldtype_conditional_render-id: 'pu_costs' fieldtype_conditional: 'textbox' mandatory: true diff --git a/inst/glossary_table.csv b/inst/glossary_table.csv new file mode 100644 index 0000000..dfde675 --- /dev/null +++ b/inst/glossary_table.csv @@ -0,0 +1,14 @@ +Term,Abbreviation,Definition,Reference +Planning unit,PU,The spatial- or spatial-temporal geographical unit over which a decision is made. Typical examples include a grid cell or vector shape (such as farmland or country borders).,Authors +Target,T,An explicit parameter quantifying the desired representation of a given feature in the prioritization. ,"Adapted from Margules, C. R., & Sarkar, S. (2007). Systematic conservation planning. Cambridge University Press. " +Representation,,Can be measured as the fraction of features that meet their set of targets. Or alternatively if targets have not been formulated as the fraction of the total amount of a feature covered by a solution.,"Adapted from Margules, C. R., & Sarkar, S. (2007). Systematic conservation planning. Cambridge University Press. " +Features,F,A set of quantitative datasets included in the planning process and over which priorities should be identified. Examples include for example spatial[-temporal] estimates of species distribution or abundance.,Authors +Systematic conservation planning,SCP,"Systematic conservation planning consists of the use of protocols to identify areas or actions that should have priority for the allocation of [scarce] management resources and separate them from processes which threaten their persistence. Systematic conservation planning is usually implemented with software tools using digital georeferenced data sets and area-selection algorithms. It is a structured step-wise approach to mapping conservation area networks, with feedback, revision and reiteration, where needed, at any stage.","Adapted from Margules, C. R., & Sarkar, S. (2007). Systematic conservation planning. Cambridge University Press. " +Spatial prioritization,,Synonym for the application of an area- or action based algorithm for identifying priority areas. Distinct SCP as it captures only the statistical part of any planning exercise.,Authors +Solution,s,A single output from a spatial prioritization process.,Authors +Cost,c,A [spatial-explicit] estimate of the cost of selecting a given area or action as a priority.,Authors +Complementarity,,Measure of the contribution of an area in a planning region towards the full complement of [biodiversity] features. A set of complementary planning units in a solution increase the likelihood for a conservation network [or action[ to be comprehensive.,"Adapted from Margules, C. R., & Sarkar, S. (2007). Systematic conservation planning. Cambridge University Press. And Wilson, K.A., Cabeza, M. and Klein, C.J., 2009. Fundamental concepts of spatial conservation prioritization. Spatial conservation prioritization: Quantitative methods and computational tools, pp.16-27." +Comprehensiveness,,Defined as a set of priority areas that include at a minimum a portion of every feature used in the planning.,"Wilson, K.A., Cabeza, M. and Klein, C.J., 2009. Fundamental concepts of spatial conservation prioritization. Spatial conservation prioritization: Quantitative methods and computational tools, pp.16-27." +Cost-efficiency,,"A cost-efficient network of priority areas is one that is comprehensive, representative, and/or adequate for the least possible cost. Cost-efficiency is important because it facilitates future expansion of a network of priority areas through the prudent use of conservation resources and is more likely to be defensible in light of competing interests","Wilson, K.A., Cabeza, M. and Klein, C.J., 2009. Fundamental concepts of spatial conservation prioritization. Spatial conservation prioritization: Quantitative methods and computational tools, pp.16-27." +Irreplaceability,,Measures the value of the inclusion of a planning unit in a solution relative to specified targets and other constraints.,"Wilson, K.A., Cabeza, M. and Klein, C.J., 2009. Fundamental concepts of spatial conservation prioritization. Spatial conservation prioritization: Quantitative methods and computational tools, pp.16-27." +Constraint,,A constraint placed on whether or to what extent a given area can be selected as priority.,Authors