Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Issue 125 help popups #132

Merged
merged 7 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions R/app_utils_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,42 @@ updateGet_file_ui <- function(inputId, value, ...){
NULL
}

check_comment_ui <- function(id, label, com = "", ...){
guide_popup <- function(id){
id <- stringr::str_remove(id, "help_")

sec <- stringr::str_extract(id, "^[B-D]")
q <- stringr::str_extract(id, "\\d")
q1 <- stringr::str_extract(id, "[a-h]")
q2 <- stringr::str_extract(id, "i+")

txt <- guideline_lu_tbl %>% filter(section == sec, question == q |is.na(question),
sub_question == q1 | is.na(sub_question),
sub2_question == q2 | is.na(sub2_question)) %>%
pull(guide_text) %>% paste(collapse = "\n")

ttl <- vulnq_code_lu_tbl %>% filter(Code == id) %>% pull(Question)

showModal(modalDialog(title = ttl, HTML({txt})))
}


check_comment_ui <- function(id, label, com = "", guide = TRUE, ...){
if(guide){
chkbxIn <- fluidRow(
column(9, checkboxGroupInput(id, label, inline = TRUE, ...)),
column(1, actionButton(paste0("help_", id), label = "", icon = icon("info")))
)
} else {
chkbxIn <- checkboxGroupInput(id, label, inline = TRUE, ...)
}

div(id = paste0(id, "div"),
checkboxGroupInput(id, label, inline = TRUE, ...),
chkbxIn,
#decrease whitespace b/w elements
div(style = "margin-top: -1.5em"),
textAreaInput(paste0("com", id), label = NULL, placeholder = "Comments",
value = com)
)

}

updateCheck_comment_ui <- function(inputId, value, com, session){
Expand Down
39 changes: 14 additions & 25 deletions R/ccvi_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ ccvi_app <- function(testmode_in, ...){
h4("Section B: Indirect Exposure to Climate Change"),
h4("Evaluate for specific geographical area under consideration"),
h5("Factors that influence vulnerability"),
actionButton("guideB", "Show guidelines"),
check_comment_ui("B1", "1) Exposure to sea level rise:",
choiceNames = valueNms,
choiceValues = valueOpts),
Expand All @@ -306,7 +305,6 @@ ccvi_app <- function(testmode_in, ...){
div(
id = "secC",
h4("Section C: Sensitivity and Adaptive Capacity"),
actionButton("guideC", "Show guidelines"),
check_comment_ui("C1", "1) Dispersal and movements",
choiceNames = valueNms,
choiceValues = valueOpts),
Expand Down Expand Up @@ -395,7 +393,6 @@ ccvi_app <- function(testmode_in, ...){
id = "secD",
h4("Section D: Documented or Modeled Response to Climate Change"),
h5("(Optional; May apply across the range of a species)"),
actionButton("guideD", "Show guidelines"),

check_comment_ui("D1", "1) Documented response to recent climate change. ",
choiceNames = valueNms,
Expand All @@ -418,7 +415,6 @@ ccvi_app <- function(testmode_in, ...){
12,
h3("Spatial Vulnerability Questions"),
h4("Section C: Sensitivity and Adaptive Capacity"),
actionButton("guideC2", "Show guidelines"),
br(),
spat_vuln_ui(
id = "C2ai",
Expand All @@ -434,16 +430,17 @@ ccvi_app <- function(testmode_in, ...){
vuln_q_nm = "2b) i) Historical hydrological niche."
),
h4("Section D: Documented or Modeled Response to Climate Change"),
actionButton("guideD2", "Show guidelines"),
br(),
spat_vuln_ui(
id = "D2_3",
header = "Modeled future range change",
chk_box = FALSE
),
strong("2) Modeled future (2050) change in population or range size."),
fluidRow(column(9, strong("2) Modeled future (2050) change in population or range size.")),
column(1, actionButton(paste0("help_", "D2"), label = "", icon = icon("info")))),
uiOutput("box_D2"),
strong("3) Overlap of modeled future (2050) range with current range"),
fluidRow(column(9, strong("3) Overlap of modeled future (2050) range with current range"),),
column(1, actionButton(paste0("help_", "D3"), label = "", icon = icon("info")))),
uiOutput("box_D3"),
actionButton("next5", "Next", class = "btn-primary")
)
Expand Down Expand Up @@ -1080,16 +1077,13 @@ ccvi_app <- function(testmode_in, ...){

# Vulnerability Qs #===============
# Show guidelines with additional info for each section
observeEvent(input$guideB, {
guideB()
})

observeEvent(input$guideC, {
guideCNonSpatial()
})
observe({
help_ins <- stringr::str_subset(names(input), "help")

observeEvent(input$guideD, {
guideDNonSpatial()
purrr::map(help_ins,
~observeEvent(input[[.x]], {
guide_popup(.x)
}, ignoreInit = TRUE))
})

# When next button is clicked move to next panel
Expand All @@ -1100,13 +1094,6 @@ ccvi_app <- function(testmode_in, ...){
})

# Spatial Vulnerability Questions #========================
observeEvent(input$guideC2, {
guideCSpatial()
})

observeEvent(input$guideD2, {
guideDSpatial()
})

# C2ai
observe({spat_vuln_hide("C2ai", clim_vars()$htn, doSpatial(), restored_df(), spat_res()$HTN_1)})
Expand Down Expand Up @@ -1256,7 +1243,8 @@ ccvi_app <- function(testmode_in, ...){
choiceNames = valueNms,
choiceValues = valueOpts,
selected = box_val,
com = prevCom)
com = prevCom,
guide = FALSE)
}

})
Expand All @@ -1283,7 +1271,8 @@ ccvi_app <- function(testmode_in, ...){
choiceNames = valueNms,
choiceValues = valueOpts,
selected = box_val,
com = prevCom)
com = prevCom,
guide = FALSE)
}

})
Expand Down
2 changes: 1 addition & 1 deletion R/guidelines.R
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ guideExposure <- function(){
The Index treats exposure to climate change as a modifier of sensitivity and
adaptive capacity. If the climate in a given assessment area will not change
much, none of the sensitivity/adaptive capacity factors will weigh heavily,
and a species is likely to score at the Not Vulnerable end of the range.
and a species is likely to score at the Less Vulnerable end of the range.
A large change in temperature or moisture availability will amplify the effect
of any related sensitivity/adaptive capacity factor, and will contribute
to a score reflecting higher vulnerability to climate change. In most cases,
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
28 changes: 28 additions & 0 deletions data-raw/Code_Q_lookup.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Code,Question,Max_Value,is_spatial
B1, 1) Exposure to sea level rise ,3,0
B2a, a) Natural barriers,3,0
B2b, b) Anthropogenic barriers,3,0
B3, 3) Predicted impact of land use changes resulting from human responses to climate change,2,0
C1, 1) Dispersal and movements ,3,0
C2ai,i) historical thermal niche,3,1
C2aii,ii) physiological thermal niche,3,1
C2bi,i) historical hydrological niche,3,1
C2bii,ii) physiological hydrological niche,3,0
C2c, c) Dependence on a specific disturbance regime likely to be impacted by climate change,2,0
C2d," d) Dependence on ice, ice-edge, or snow-cover habitats",3,0
C3, 3) Restriction to uncommon landscape/geological features or derivatives,2,0
C4a, a) Dependence on other species to generate required habitat,2,0
C4b, b) Dietary versatility (animals only),2,0
C4c, c) Pollinator versatility (plants only),2,0
C4d, d) Dependence on other species for propagule dispersal,2,0
C4e, e) Sensitivity to pathogens or natural enemies,2,0
C4f, f) Sensitivity to competition from native or non-native species,2,0
C4g, g) Forms part of an interspecific interaction not covered by 5a-f,2,0
C5a, a) Measured genetic variation ,2,0
C5b," b) Occurrence of bottlenecks in recent evolutionary history (use only if 5a is ""unknown"")",2,0
C5c, c) Reproductive system (plants only; use only if C5a and C5b are "unknown") ,2,0
C6, 6) Phenological response to changing seasonal temperature and precipitation dynamics,2,0
D1, 1) Documented response to recent climate change ,3,0
D2, 2) Modeled future (2050) change in population or range size ,3,1
D3, 3) Overlap of modeled future (2050) range with current range,3,1
D4, 4) Occurrence of protected areas in modeled future (2050) distribution,2,0
Loading