| Title: | SDM Evaluation Tool Shiny UI |
|---|---|
| Description: | The goal of sdmEvalToolUI is to implement Shiny functionality according to the SDM Evaluation Tool requirements to evaluate materials. |
| Authors: | Peter Solymos [aut, cre] (ORCID: <https://orcid.org/0000-0001-7337-1740>), Steffi LaZerte [aut] (ORCID: <https://orcid.org/0000-0002-7690-8360>), Analythium Solutions Inc. [cph], His Majesty the King in Right of Canada as represented by the Minister of the Environment [cph] (Copyright holder for default evaluation/drill down questions.), Biodiversity Pathways [cph] (Copyright holder for glossary.csv, and default evaluation/drill down questions.), Alberta Biodiversity Monitoring Institute [cph] (Copyright holder for glossary.csv, and default evaluation/drill down questions.) |
| Maintainer: | Peter Solymos <[email protected]> |
| License: | Apache License 2.0 |
| Version: | 0.0.1 |
| Built: | 2026-10-01 07:40:24 UTC |
| Source: | https://github.com/LandSciTech/sdmEvaluationTool |
Add Layers control to map
add_control(map, groups = character(0))add_control(map, groups = character(0))
map |
Leaflet map |
groups |
Character vector. Layers or Group names to add to the control. Subunits are included by default. Only existing layers are included. |
Leaflet map with layer control buttons
# No subunits r <- template_spatial_prep() base_map() |> add_raster(r, layer = "mean", palette = "viridis", name = "Mean") |> add_control(groups = "Mean") # With subunits if(have_data()) { r <- template_spatial_prep() s <- deployment_subunits_prep("deployment1") base_map() |> add_raster(r, layer = "mean", palette = "viridis", name = "Mean") |> add_subunits(s) |> add_control(groups = "Mean") }# No subunits r <- template_spatial_prep() base_map() |> add_raster(r, layer = "mean", palette = "viridis", name = "Mean") |> add_control(groups = "Mean") # With subunits if(have_data()) { r <- template_spatial_prep() s <- deployment_subunits_prep("deployment1") base_map() |> add_raster(r, layer = "mean", palette = "viridis", name = "Mean") |> add_subunits(s) |> add_control(groups = "Mean") }
Add point markers to Leaflet map
add_markers( map, data = leaflet::getMapData(map), colour_by = "layers", layer_by = "layers" )add_markers( map, data = leaflet::getMapData(map), colour_by = "layers", layer_by = "layers" )
map |
Leaflet map object. |
data |
Spatial data with markers to plot (defaults to data in the |
colour_by |
Character. Column to use when colouring points. |
layer_by |
Character. Column to use to group points into layers (for
|
Leaflet map.
base_map() |> add_markers(data = test_points()) |> add_control(groups = c("present", "absent")) # From 'layers' columnbase_map() |> add_markers(data = test_points()) |> add_control(groups = c("present", "absent")) # From 'layers' column
Note that raster layers are attached to a new map pane with a defined
z-index. This is so we can be sure the raster is above the map tiles (z-index
200, see base_map()), and yet below the subunits (default z-index of 400).
add_raster( map, raster, layer, name, palette, opacity = 0.8, add_legend = TRUE, min_0 = TRUE )add_raster( map, raster, layer, name, palette, opacity = 0.8, add_legend = TRUE, min_0 = TRUE )
map |
Leaflet map |
raster |
Terra raster to add |
layer |
Layer in raster to add |
name |
Name of leaflet layer (for controls and ids) |
palette |
Character. Colour palette to use |
opacity |
Numeric. Opacity of raster layer |
add_legend |
Logical. Whether or not to add a legend. |
min_0 |
Logical. Whether to force the legend to start at zero. |
Leaflet map
r <- template_spatial_prep() base_map() |> add_raster(r, layer = "mean", palette = "viridis", name = "Mean")r <- template_spatial_prep() base_map() |> add_raster(r, layer = "mean", palette = "viridis", name = "Mean")
Very similar to add_markers() but colours according to type column which
defines the selections and no option to add to controls.
add_selected_markers(map, data = leaflet::getMapData(map), colour_by = "type")add_selected_markers(map, data = leaflet::getMapData(map), colour_by = "type")
map |
Leaflet map object. |
data |
Spatial data with markers to plot (defaults to data in the |
colour_by |
Character. Column to use when colouring points. |
Leaflet map.
base_map() |> add_selected_markers(data = test_points())base_map() |> add_selected_markers(data = test_points())
Similar to add_subunits() but colours subunits by fill colour and selection
type.
add_selected_subunits( map, subunits = NULL, colour_by = "type", opacity = 0.8, fill_opacity = 0.2 )add_selected_subunits( map, subunits = NULL, colour_by = "type", opacity = 0.8, fill_opacity = 0.2 )
map |
Leaflet map object. |
subunits |
Spatial Data Frame. Subunits |
colour_by |
Vector. Column to fill by (must be a factor with levels to get the correct legend). |
opacity, fill_opacity
|
Numeric. Opacity. |
subunits <- deployment_subunits_prep("deployment1") |> dplyr::mutate( type = c(rep("Very biased", 10), rep("Moderately biased", 10), rep(NA, 114)), type = factor(type) ) base_map() |> add_selected_subunits(subunits)subunits <- deployment_subunits_prep("deployment1") |> dplyr::mutate( type = c(rep("Very biased", 10), rep("Moderately biased", 10), rep(NA, 114)), type = factor(type) ) base_map() |> add_selected_subunits(subunits)
Add subunits to Leaflet map
add_subunits(map, subunits = NULL, colour_by = "subunit_id", opacity = 0.8)add_subunits(map, subunits = NULL, colour_by = "subunit_id", opacity = 0.8)
map |
Leaflet map object. |
subunits |
Spatial Data Frame. Subunits |
colour_by |
Vector. Column to fill by |
opacity |
Numeric. Opacity. |
subunits <- deployment_subunits_prep("deployment1") base_map() |> add_subunits(subunits)subunits <- deployment_subunits_prep("deployment1") base_map() |> add_subunits(subunits)
Used to determine which parts should be displayed
affirmative(type = "standard")affirmative(type = "standard")
type |
Character. "standard" (currently for ordinal inputs), or "spatial" |
Character vector of affirmative answers
affirmative() affirmative("spatial")affirmative() affirmative("spatial")
Get all materials available
app_materials()app_materials()
Data frame of all materials available
app_materials()app_materials()
Get Users details
app_users()app_users()
Data frame of user details
app_users()app_users()
Create the base Leaflet map with standard tiles, selection draw toolbar and
erase selection button. Also includes and custom Javascripts, here one for
marking which layers are visible for use in selections filtering (see
mod_utils_map_selections_server()).
base_map(ns = identity)base_map(ns = identity)
ns |
Namespace. Required for spatial selections. |
base_map()base_map()
sdm_card() - Wrapper for bslib::card(), provides defaults for class,
full_screen and min_height.
sdm_card_header() - Wrapper for bslib::card_header(), provides default
custom class (see sdm_theme()).
sdm_nav_panel() - Wrapper for bslib::nav_panel(), provides default
custom class (see sdm_theme()).
sdm_layout_sidebar() - Wrapper for bslib::layout_sidebar(), provides
defaults for gap and border.
sdm_card(..., class = "p-0", full_screen = TRUE, min_height = 400) sdm_card_header(..., class = "bg-sdm") sdm_nav_panel(title, ..., class = "sdm-tab-pane") sdm_layout_sidebar(..., gap = 0, border = FALSE)sdm_card(..., class = "p-0", full_screen = TRUE, min_height = 400) sdm_card_header(..., class = "bg-sdm") sdm_nav_panel(title, ..., class = "sdm-tab-pane") sdm_layout_sidebar(..., gap = 0, border = FALSE)
... |
See bslib function |
class |
Character vector. HTML classes to add to the card. |
full_screen |
Logical. Option to make card full screen. |
min_height |
Numeric. Minimum card height. |
title |
Character. Nav panel title. |
gap |
Numeric. Vertical gap between sidebar elements. |
border |
Logical. Whether or not to add a border. |
bslib function output
Compares the number of questions from those evaluated (q2) to those
calculated from the question data (q1). Questions from evaluated (q2) may
be NA if evaluations haven't been finished. Will error if values don't
match (ignoring NAs).
check_q_mismatch(q1, q2)check_q_mismatch(q1, q2)
q1 |
Vector of Integers. Number of questions calculated from Question data (total questions available). |
q2 |
Vector of Integers. Number of questions evaluated. |
invisible or error if there is a mismatch.
check_q_mismatch(c(1, 1, 2, 10, 6), c(1, 1, 2, 10, 6)) check_q_mismatch(c(10, 7, 1), c(10, NA, NA)) # check_q_mismatch(c(10, 11, 1), c(10, 10, NA)) # Errorcheck_q_mismatch(c(1, 1, 2, 10, 6), c(1, 1, 2, 10, 6)) check_q_mismatch(c(10, 7, 1), c(10, NA, NA)) # check_q_mismatch(c(10, 11, 1), c(10, 10, NA)) # Error
For use when drawing selections.
coords_to_poly(geometry)coords_to_poly(geometry)
geometry |
From drawing selections. |
Sf polygon
Put the checks here rather than sdmEvalToolCore to avoid Shiny dependency in core package.
db_connect_check(dbname = NULL, ...)db_connect_check(dbname = NULL, ...)
dbname |
DB name. |
... |
Arguments passed to |
A database connection.
Create a Leaflet Map of Subunits
deployment_subunits_map(subunits, ns = identity)deployment_subunits_map(subunits, ns = identity)
subunits |
Spatial Data frame. Deployment subunits. |
ns |
Namespace. |
A leaflet map object
s <- deployment_subunits_prep("deployment1") deployment_subunits_map(s)s <- deployment_subunits_prep("deployment1") deployment_subunits_map(s)
Subunits are used by multiple mapping components for a deployment.
deployment_subunits_prep(deployment_id)deployment_subunits_prep(deployment_id)
deployment_id |
Character. Deployment ID |
Subunits polygons
deployment_subunits_prep(deployment_id = "deployment1")deployment_subunits_prep(deployment_id = "deployment1")
Summarizes evaluation data to count total questions and completed questions.
evals_answered(eval)evals_answered(eval)
eval |
Data frame. Evaluation data with response column |
This is used by the 'overview'/'summary'/'index' page.
Data frame with columns: n_q (total questions), n_q_complete (completed questions)
eval_data <- evals_extract(test_evaluation_body()) evals_answered(eval_data) eval_data <- evals_extract(test_evaluation_body(component_id = "model_fit_a")) evals_answered(eval_data) eval_data <- evals_extract(test_evaluation_body(component_id = "model_fit_b")) evals_answered(eval_data)eval_data <- evals_extract(test_evaluation_body()) evals_answered(eval_data) eval_data <- evals_extract(test_evaluation_body(component_id = "model_fit_a")) evals_answered(eval_data) eval_data <- evals_extract(test_evaluation_body(component_id = "model_fit_b")) evals_answered(eval_data)
Retrieves evaluation details for a specific user based on their role. For modelers, shows all evaluations across users for their deployments. For evaluators, shows only their own evaluations. Returns a data frame with deployment, model, species, component, and completion information.
evals_details(user_id, user_role)evals_details(user_id, user_role)
user_id |
Character string. User identifier |
user_role |
Character string. User role ("modeler" or "evaluator") |
This is used by the 'overview'/'summary'/'index' page.
Data frame with columns:
deployment_model_name
evaluation_create_user_name
deployment_name
model_name
species_display
component_name
completed
started
n_q_display
n_q
n_q_complete
evals_details("testuser", "evaluator") evals_details("testuser", "modeler")evals_details("testuser", "evaluator") evals_details("testuser", "modeler")
Parses JSON-formatted evaluation body into a data frame. Opposite of
response_to_json().
evals_extract(json)evals_extract(json)
json |
Character. JSON-formatted evaluation data |
Data frame with evaluation information
evals_extract(test_evaluation_body())evals_extract(test_evaluation_body())
For comparing questions to Shiny input answers, convert the questions to the same input list structure as returned in the Shiny app.
evals_list(questions)evals_list(questions)
questions |
Data frame. Data frame of questions; output of
|
List which imitates a Shiny input object
q <- prep_questions( "observations", "deployment1", "bam_v5_can71", "BBWA", "testuser" ) evals_list(q) q <- prep_questions( "model_summary", "deployment1", "bam_v5_can71", "BBWA", "testuser" ) evals_list(q)q <- prep_questions( "observations", "deployment1", "bam_v5_can71", "BBWA", "testuser" ) evals_list(q) q <- prep_questions( "model_summary", "deployment1", "bam_v5_can71", "BBWA", "testuser" ) evals_list(q)
Creates reactable table displaying evaluation progress for either modelers or evaluators. The table shows deployment-model combinations, species, components, and their completion status.
evals_table(tbl, user_role)evals_table(tbl, user_role)
tbl |
Data frame. Evaluation details from |
user_role |
Character. User role ("modeler", or "evaluator") |
A reactable table object
tbl <- evals_details("testuser", "evaluator") evals_table(tbl, "evaluator")tbl <- evals_details("testuser", "evaluator") evals_table(tbl, "evaluator")
Extract feature ids
feature_ids(features)feature_ids(features)
features |
The input for the draw all features
( |
Numeric vector of leaflet ids
If deployment doesn't exist, uses sdmEvalToolCore::default_questions().
fetch_questions(deployment_id, component_id)fetch_questions(deployment_id, component_id)
deployment_id |
Character. Deployment ID |
component_id |
Character. Component ID |
Data frame of questions.
# Use default questions if deployment doesn't exist fetch_questions("No deployment", "observations") if(have_data()) { fetch_questions("deployment1", "observations") }# Use default questions if deployment doesn't exist fetch_questions("No deployment", "observations") if(have_data()) { fetch_questions("deployment1", "observations") }
Format species display names
fmt_species(df)fmt_species(df)
df |
Data frame to format. Must contain at least species name in French or English as well as scientific name. |
Formatted species display names.
Format time nicely for humans
fmt_time(time)fmt_time(time)
time |
POSIXct time |
Character. Nicely formated date
fmt_time(Sys.time()) fmt_time(as.POSIXct("2026-02-01 16:02"))fmt_time(Sys.time()) fmt_time(as.POSIXct("2026-02-01 16:02"))
Get Material Settings
get_material_settings(x)get_material_settings(x)
x |
Object. |
The value of the material settings attribute
Checks whether the user has local data available for this tool. Used for examples (must be exported).
have_data()have_data()
TRUE/FALSE
have_data()have_data()
Used in mod_utils_evaluations_server() to loosely determine if evaluations
are identical between saved and inputs (to determine if the unsaved notice
should be used).
identical_loose(i1, i2)identical_loose(i1, i2)
i1 |
Character |
i2 |
Character |
Logical
Helper function to format Shiny Input names as Question Values
input_to_value(i)input_to_value(i)
i |
Character vector of Input names |
Character string of Shiny Inputs names formatted as Question values
input_to_value("Strongly_Agree")input_to_value("Strongly_Agree")
Return the app language
lang()lang()
Character. Either "english" or "french"
lang()lang()
Note: this only works for Leaflet maps, NOT Leaflet Proxies.
For example, this is why mod_comp_predictor_raster family of functions
are a bit convoluted when it calls to adding layers and controls (because
add_controls() only adds layers which are detected with this function).
map_has_group(map, group)map_has_group(map, group)
map |
Leaflet Map (not Leaflet Proxy). |
group |
Character Vector. Groups to check for. |
This may be slightly fragile if the list structure of the leaflet objects change.
Logical. True if detected, false otherwise.
Tracks interactive inputs from map selections. Depending on the origin, namespaced if necessary.
map_reactive_vals( input, map, x = c("draw_all_features", "draw_new_feature", "draw_stop", "marker_click", "shape_click"), js_x = c("clear_selection", "layers_visible") )map_reactive_vals( input, map, x = c("draw_all_features", "draw_new_feature", "draw_stop", "marker_click", "shape_click"), js_x = c("clear_selection", "layers_visible") )
input |
Shiny input object. |
map |
Character. Map name. |
x |
Character vector. Names of interactive inputs which are namespaced to the map, so must be namespaced here. |
js_x |
Character vector. Names of Javascript created interactive inputs which do not need to be namespaced. |
Used at the component-level for those using spatial selections.
A reactiveValues() list, as well as having the side effect of creating
shiny::observe() for each value in the list to be independently updated.
Deployment Subunits component Server
mod_comp_deployment_subunits_server( id = "comp_summary", parent_id, deployment_id, model_id, species_id, spatial_selection, spatial_ids, map_views )mod_comp_deployment_subunits_server( id = "comp_summary", parent_id, deployment_id, model_id, species_id, spatial_selection, spatial_ids, map_views )
id |
Module ID |
parent_id |
Parent tab ID (used to identify which tab is active) |
deployment_id |
Deployment ID |
model_id |
Model ID |
species_id |
Species ID |
spatial_selection |
Spatial selection |
spatial_ids |
Spatial IDs |
map_views |
List. List of reactiveVals |
Module server function
Deployment Subunits Component UI
mod_comp_deployment_subunits_ui(id = "comp_summary", header = "Comfort zones")mod_comp_deployment_subunits_ui(id = "comp_summary", header = "Comfort zones")
id |
Shiny module ID |
header |
Header |
Shiny UI
mod_comp_deployment_subunits_ui()mod_comp_deployment_subunits_ui()
Model Fit Component Server
mod_comp_model_fit_server(id = "comp_model_fit", model_id, species_id)mod_comp_model_fit_server(id = "comp_model_fit", model_id, species_id)
id |
Module ID |
model_id |
Model ID |
species_id |
Species ID |
Module server function
Model Fit Component UI
mod_comp_model_fit_ui(id = "comp_model_fit", header = "Model Fit")mod_comp_model_fit_ui(id = "comp_model_fit", header = "Model Fit")
id |
Shiny module ID |
header |
Header |
Shiny UI
mod_comp_model_fit_ui()mod_comp_model_fit_ui()
Model Summary component Server
mod_comp_model_summary_server(id = "comp_model_summary", model_id, species_id)mod_comp_model_summary_server(id = "comp_model_summary", model_id, species_id)
id |
Module ID |
model_id |
Model ID |
species_id |
Species ID |
Module server function
Model Summary Component UI
mod_comp_model_summary_ui(id = "comp_model_summary", header = "Model Summary")mod_comp_model_summary_ui(id = "comp_model_summary", header = "Model Summary")
id |
Shiny module ID |
header |
Header |
Shiny UI
mod_comp_model_summary_ui()mod_comp_model_summary_ui()
Observations Chart Component Server
mod_comp_obs_chart_server(id = "comp_obs_chart", model_id, species_id)mod_comp_obs_chart_server(id = "comp_obs_chart", model_id, species_id)
id |
Module ID |
model_id |
Model ID |
species_id |
Species ID |
Module server function
Observations Chart Component UI
mod_comp_obs_chart_ui(id = "comp_obs_chart", header = "Observation Charts")mod_comp_obs_chart_ui(id = "comp_obs_chart", header = "Observation Charts")
id |
Character. Shiny module ID |
header |
Header |
Shiny UI
mod_comp_obs_chart_ui()mod_comp_obs_chart_ui()
Observations component Server
mod_comp_observations_server( id = "comp_observations", parent_id, deployment_id, model_id, species_id, spatial_selection, spatial_ids, map_views )mod_comp_observations_server( id = "comp_observations", parent_id, deployment_id, model_id, species_id, spatial_selection, spatial_ids, map_views )
id |
Module ID |
parent_id |
Parent tab ID (used to identify which tab is active) |
deployment_id |
Deployment ID. Required for subunits. |
model_id |
Model ID |
species_id |
Species ID |
spatial_selection |
Spatial selection |
spatial_ids |
Spatial IDs |
map_views |
List. List of reactiveVals |
Module server function
Observations Component UI
mod_comp_observations_ui( id = "comp_observations", header = "Map of Observations" )mod_comp_observations_ui( id = "comp_observations", header = "Map of Observations" )
id |
Character. Shiny module ID |
header |
Header |
Shiny UI
mod_comp_observations_ui()mod_comp_observations_ui()
Predictor Metadata component Server
mod_comp_predictor_metadata_server(id = "comp_predictor_metadata", model_id)mod_comp_predictor_metadata_server(id = "comp_predictor_metadata", model_id)
id |
Module ID |
model_id |
Model ID |
Module server function
Predictor Metadata Component UI
mod_comp_predictor_metadata_ui( id = "comp_predictor_metadata", height = "40%", header = "Predictor Metadata" )mod_comp_predictor_metadata_ui( id = "comp_predictor_metadata", height = "40%", header = "Predictor Metadata" )
id |
Shiny module ID |
height |
Height |
header |
Header |
Shiny UI
mod_comp_predictor_metadata_ui()mod_comp_predictor_metadata_ui()
Predictor Raster component Server
mod_comp_predictor_raster_server( id = "comp_predictor_raster", parent_id, deployment_id, model_id, map_views )mod_comp_predictor_raster_server( id = "comp_predictor_raster", parent_id, deployment_id, model_id, map_views )
id |
Module ID |
parent_id |
Parent tab ID (used to identify which tab is active) |
deployment_id |
Deployment ID. Required for subunits. |
model_id |
Model ID |
map_views |
List. List of reactiveVals |
Module server function
Predictor Raster Component UI
mod_comp_predictor_raster_ui( id = "comp_predictor_raster", height = NULL, header = "Predictor Raster" )mod_comp_predictor_raster_ui( id = "comp_predictor_raster", height = NULL, header = "Predictor Raster" )
id |
Shiny module ID |
height |
Height |
header |
Header |
Shiny UI
mod_comp_predictor_raster_ui()mod_comp_predictor_raster_ui()
Spatial Prediction component Server
mod_comp_spatial_prediction_server( id = "comp_spatial_prediction", parent_id, deployment_id, model_id, species_id, spatial_selection, spatial_ids, map_views )mod_comp_spatial_prediction_server( id = "comp_spatial_prediction", parent_id, deployment_id, model_id, species_id, spatial_selection, spatial_ids, map_views )
id |
Module ID |
parent_id |
Parent tab ID (used to identify which tab is active) |
deployment_id |
Deployment ID. Required for subunits. |
model_id |
Model ID |
species_id |
Species ID |
spatial_selection |
Spatial selection. Required for spatial evaluations |
spatial_ids |
Spatial IDs. Required for spatial evaluations. |
map_views |
List. List of reactiveVals |
Module server function
Spatial Prediction Component UI
mod_comp_spatial_prediction_ui( id = "comp_spatial_prediction", header = "Predictions" )mod_comp_spatial_prediction_ui( id = "comp_spatial_prediction", header = "Predictions" )
id |
Shiny module ID |
header |
Header |
Shiny UI
mod_comp_spatial_prediction_ui()mod_comp_spatial_prediction_ui()
Template component Server
mod_comp_template_server(id = "comp_template", model_id, species_id)mod_comp_template_server(id = "comp_template", model_id, species_id)
id |
Module ID |
model_id |
Model ID |
species_id |
Species ID |
Module server function
Template Spatial component Server
mod_comp_template_spatial_server( id = "comp_template_spatial", parent_id, deployment_id, model_id, species_id, spatial_selection, spatial_ids, map_views )mod_comp_template_spatial_server( id = "comp_template_spatial", parent_id, deployment_id, model_id, species_id, spatial_selection, spatial_ids, map_views )
id |
Module ID |
parent_id |
ID of the parent module, corresponds to the tab. |
deployment_id |
Deployment ID. Required for subunits. |
model_id |
Model ID |
species_id |
Species ID |
spatial_selection |
Spatial selection. Required for spatial evaluations. |
spatial_ids |
Spatial IDs. Required for spatial evaluations. |
map_views |
List. List of reactiveVals |
Module server function
Template Spatial Component UI
mod_comp_template_spatial_ui( id = "comp_template_spatial", header = "Template Spatial" )mod_comp_template_spatial_ui( id = "comp_template_spatial", header = "Template Spatial" )
id |
Character. Shiny module ID |
header |
Header |
Shiny UI
mod_comp_template_spatial_ui()mod_comp_template_spatial_ui()
Template Component UI
mod_comp_template_ui(id = "comp_template", header = "Template")mod_comp_template_ui(id = "comp_template", header = "Template")
id |
Shiny module ID |
header |
Header |
Shiny UI
mod_comp_template_ui()mod_comp_template_ui()
Model Page Server
mod_page_model_server(id = "model", ...)mod_page_model_server(id = "model", ...)
id |
Shiny module ID |
... |
Additional arguments passed via expand_dots including
|
Server function for Shiny module
Model Page UI
mod_page_model_ui(id, title, review_width = NULL)mod_page_model_ui(id, title, review_width = NULL)
id |
Shiny module ID |
title |
Page title |
review_width |
Review width |
Shiny UI
mod_page_model_ui("id", "title")mod_page_model_ui("id", "title")
Observations Page Server
mod_page_observations_server(id = "observations", ...)mod_page_observations_server(id = "observations", ...)
id |
Shiny module ID |
... |
Additional arguments passed via expand_dots including
|
Server function for Shiny module
Observations Page UI
mod_page_observations_ui(id, title, review_width = NULL)mod_page_observations_ui(id, title, review_width = NULL)
id |
Shiny module ID |
title |
Page title |
review_width |
Character. Width of the review sidebar in percentage of the screen |
Shiny UI
mod_page_observations_ui("id", "title")mod_page_observations_ui("id", "title")
Overview Page Server
mod_page_overview_server(id = "overview", ...)mod_page_overview_server(id = "overview", ...)
id |
Shiny module ID |
... |
Additional arguments passed via expand_dots including
|
Server function for Shiny module
Overview Page UI
mod_page_overview_ui(id, title)mod_page_overview_ui(id, title)
id |
Shiny module ID |
title |
Page title |
Shiny UI
mod_page_overview_ui("id", "title")mod_page_overview_ui("id", "title")
Predictions Page Server
mod_page_predictions_server(id = "predictions", ...)mod_page_predictions_server(id = "predictions", ...)
id |
Shiny module ID |
... |
Additional arguments passed via expand_dots including
|
Server function for Shiny module
Predictions Page UI
mod_page_predictions_ui(id, title, review_width = NULL)mod_page_predictions_ui(id, title, review_width = NULL)
id |
Shiny module ID |
title |
Page title |
review_width |
Review width |
Shiny UI
mod_page_predictions_ui("id", "title")mod_page_predictions_ui("id", "title")
Predictors Page Server
mod_page_predictors_server(id = "predictors", ...)mod_page_predictors_server(id = "predictors", ...)
id |
Shiny module ID |
... |
Additional arguments passed via expand_dots including
|
Server function for Shiny module
Predictors Page UI
mod_page_predictors_ui(id, title, review_width = NULL)mod_page_predictors_ui(id, title, review_width = NULL)
id |
Shiny module ID |
title |
Page title |
review_width |
Review width |
Shiny UI
mod_page_predictors_ui("id", "title")mod_page_predictors_ui("id", "title")
Summary Page Server
mod_page_summary_server(id = "summary", ...)mod_page_summary_server(id = "summary", ...)
id |
Shiny module ID |
... |
Additional arguments passed via expand_dots including
|
Server function for Shiny module
Summary Page UI
mod_page_summary_ui(id, title, review_width = NULL)mod_page_summary_ui(id, title, review_width = NULL)
id |
Shiny module ID |
title |
Page title |
review_width |
Review width |
Shiny UI
mod_page_summary_ui("id", "title")mod_page_summary_ui("id", "title")
Template Page Server
mod_page_template_server(id = "template", ...)mod_page_template_server(id = "template", ...)
id |
Shiny module ID |
... |
Additional arguments passed via expand_dots including
|
Server function for Shiny module
Template Page Server
mod_page_template_spatial_server(id = "template_spatial", ...)mod_page_template_spatial_server(id = "template_spatial", ...)
id |
Shiny module ID. NOTE for pages this should match a value in the tabs argument of sdm_tool().f |
... |
Additional arguments passed via expand_dots including
|
Server function for Shiny module
Template Spatial Page UI
mod_page_template_spatial_ui(id, title, review_width = NULL)mod_page_template_spatial_ui(id, title, review_width = NULL)
id |
Shiny module ID |
title |
Page title |
review_width |
Review width |
Shiny UI
mod_page_template_spatial_ui("id", "title")mod_page_template_spatial_ui("id", "title")
Template Page UI
mod_page_template_ui(id, title, review_width = NULL)mod_page_template_ui(id, title, review_width = NULL)
id |
Shiny module ID |
title |
Page title |
review_width |
Review width |
Shiny UI
mod_page_template_ui("id", "title")mod_page_template_ui("id", "title")
Test Page Server
mod_page_test_server(id = "test", ...)mod_page_test_server(id = "test", ...)
id |
Shiny module ID |
... |
Additional arguments passed via expand_dots including
|
Server function for Shiny module
Test Page UI
mod_page_test_ui(id, review_width = "50%")mod_page_test_ui(id, review_width = "50%")
id |
Shiny module ID |
review_width |
Character. Width of the review sidebar in percentage. |
Shiny UI
mod_page_test_ui("id")mod_page_test_ui("id")
Used in sdm_tool() to create the Deployment Details left-hand sidebar.
mod_utils_details_server(id = "details", details)mod_utils_details_server(id = "details", details)
id |
Shiny module ID |
details |
Data frame of details to display. |
Server function for Shiny module
Used in sdm_tool() to create the Deployment Details left-hand sidebar.
mod_utils_details_ui(id = "details")mod_utils_details_ui(id = "details")
id |
Shiny module ID |
Shiny UI
mod_utils_details_ui()mod_utils_details_ui()
Utility Module 'Evaluations' Server
mod_utils_evaluations_server( id = "evaluations", component_id, deployment_id, model_id, species_id, spatial_ids = reactive(NULL), opts, abandoned, unsaved )mod_utils_evaluations_server( id = "evaluations", component_id, deployment_id, model_id, species_id, spatial_ids = reactive(NULL), opts, abandoned, unsaved )
id |
Shiny module ID |
component_id |
Character. Component ID |
deployment_id |
Character. Deployment ID |
model_id |
Character. Model ID |
species_id |
Character. Species ID |
spatial_ids |
Reactive Character vector. Spatial Ids to use when populating spatial evaluation selectizes. |
opts |
List. Options list of reactives, originates from |
abandoned |
ReactiveVal indicating whether the evaluation has been abandoned. |
unsaved |
ReactiveVal indicating whether any questions are unsaved. |
Server function for Shiny module
Called by page-level modules to create the Evaluations UI in the right-hand side bar.
mod_utils_evaluations_ui( id = "evaluations", review_width = NULL, level = "species" )mod_utils_evaluations_ui( id = "evaluations", review_width = NULL, level = "species" )
id |
Shiny module ID |
review_width |
Character. Starting width of the sidebar. |
level |
Character. Level of evaluations, "model" or "species". |
Shiny UI
Highlights spatial ids selected on the map, either through user selection or through the 'show' button from evaluations.
mod_utils_map_selections_server( id, data, spatial_selection, interactions, parent_session = getDefaultReactiveDomain() )mod_utils_map_selections_server( id, data, spatial_selection, interactions, parent_session = getDefaultReactiveDomain() )
id |
Character. Shiny module ID |
data |
Spatial Data frame. Data from which selections will be made. |
spatial_selection |
List of |
interactions |
Interactions |
parent_session |
Parent session |
Shiny server
Highlights spatial ids selected, either through user selection or through the 'show' button from evaluations. Called by component-level modules.
mod_utils_map_selections_ui(id)mod_utils_map_selections_ui(id)
id |
Character. Shiny module ID. |
Shiny UI
Synchronizes the map view port among tabs
mod_utils_map_sync_server( id, parent_id, this_view, map_views, parent_session = getDefaultReactiveDomain() )mod_utils_map_sync_server( id, parent_id, this_view, map_views, parent_session = getDefaultReactiveDomain() )
id |
Character. Shiny module ID |
parent_id |
Character. Parent tab ID (used to identify which tab is active) |
this_view |
Reactive. Reactive that returns the current map view (list with zoom and lat/lon) |
map_views |
List. List of reactiveVals |
parent_session |
Shiny session. Parent session (used for leafletProxy) |
Shiny server
Prepare Model Fit Data
model_fit_prep(model_id, species_id)model_fit_prep(model_id, species_id)
model_id |
Character. Model ID |
species_id |
Character. Species ID |
Data frame
model_fit_prep(model_ = "bam_v5_can71", species_id = "BBWO")model_fit_prep(model_ = "bam_v5_can71", species_id = "BBWO")
Create a Table for Model Fit Data
model_fit_table(model_fit)model_fit_table(model_fit)
model_fit |
Data frame with model fit information |
Reactable table
model_fit_prep(model_id = "bam_v5_can71", species_id = "BBWO") |> model_fit_table()model_fit_prep(model_id = "bam_v5_can71", species_id = "BBWO") |> model_fit_table()
Prepare Model Summary Data
model_summary_prep(model_id, species_id)model_summary_prep(model_id, species_id)
model_id |
Character. Model ID |
species_id |
Character. Species ID |
Data frame
model_summary_prep(model_id = "bam_v5_can71", species_id = "BBWO")model_summary_prep(model_id = "bam_v5_can71", species_id = "BBWO")
Create a Table for Model Summary Data
model_summary_table(model_summary)model_summary_table(model_summary)
model_summary |
Data frame. Model summary information |
A reactable table object
model_summary_prep(model_id = "bam_v5_can71", species_id = "BBWO") |> model_summary_table()model_summary_prep(model_id = "bam_v5_can71", species_id = "BBWO") |> model_summary_table()
Lists are c(named = id) to create a input selection with 'pretty' selections returning original ids.
named_ids(df_db, id = "id", name = "name", match = NULL)named_ids(df_db, id = "id", name = "name", match = NULL)
df_db |
Data frame or database where ID values can be found. |
id |
Character. Pattern matching 'id' in the column name. |
name |
Character. Pattern matching 'name' in the column name. |
match |
Character. ID/Name preface. Optional instead of |
Named character vector.
df <- data.frame( species_id = c("X11", "Y22"), species_name = c("Pretty name", "Lovely name") ) named_ids(df) named_ids(df, match = "species")df <- data.frame( species_id = c("X11", "Y22"), species_name = c("Pretty name", "Lovely name") ) named_ids(df) named_ids(df, match = "species")
Can use points or rasters to map the data.
obs_map( obs, subunits = NULL, ns = identity, output_type = c("points", "raster"), ... )obs_map( obs, subunits = NULL, ns = identity, output_type = c("points", "raster"), ... )
obs |
sf or Terra spatial data. Observations as points ( |
subunits |
Subunits |
ns |
Namespace |
output_type |
Character. Points or raster. |
... |
Other parameters. |
A leaflet map object
o <- obs_prep(model_id = "bam_v5_can71", species_id = "BBWO") s <- deployment_subunits_prep("deployment1") r0 <- prep_materials( "spatial_prediction", model_id = "bam_v5_can71", species_id = "BBWO" ) r <- obs_prep_raster(o, r0) obs_map(o, s) # points obs_map(r, s, output_type = "raster") # rastero <- obs_prep(model_id = "bam_v5_can71", species_id = "BBWO") s <- deployment_subunits_prep("deployment1") r0 <- prep_materials( "spatial_prediction", model_id = "bam_v5_can71", species_id = "BBWO" ) r <- obs_prep_raster(o, r0) obs_map(o, s) # points obs_map(r, s, output_type = "raster") # raster
Create a Leaflet Map of Observation Point Data
obs_map_points(obs, subunits = NULL, ns = identity, ...)obs_map_points(obs, subunits = NULL, ns = identity, ...)
obs |
sf data frame. Observations |
subunits |
Subunits |
ns |
Namespace |
... |
Other parameters. |
A leaflet map object
p <- test_points() obs_map_points(p)p <- test_points() obs_map_points(p)
Create a Leaflet Map of Observation Raster Data
obs_map_raster(obs, subunits = NULL, ns = identity, ...)obs_map_raster(obs, subunits = NULL, ns = identity, ...)
obs |
sf data frame. Observations |
subunits |
Subunits |
ns |
Namespace |
... |
Other parameters. |
A leaflet map object
o <- obs_prep(model_id = "bam_v5_can71", species_id = "BBWO") r <- prep_materials( "spatial_prediction", model_id = "bam_v5_can71", species_id = "BBWO" ) p <- obs_prep_raster(o, r) obs_map_raster(p)o <- obs_prep(model_id = "bam_v5_can71", species_id = "BBWO") r <- prep_materials( "spatial_prediction", model_id = "bam_v5_can71", species_id = "BBWO" ) p <- obs_prep_raster(o, r) obs_map_raster(p)
Loads and generally prepares the observation data. Wrapper around obs_prep_points() and obs_prep_raster().
obs_prep(model_id, species_id, output_type = c("points", "raster"), ...)obs_prep(model_id, species_id, output_type = c("points", "raster"), ...)
model_id |
Character. Model ID |
species_id |
Character. Species ID |
output_type |
Character. Points or raster. |
... |
Other parameters. Most importantly, |
Spatial data frame, sf if points, terra SpatRaster if raster.
r0 <- prep_materials( "spatial_prediction", model_id = "bam_v5_can71", species_id = "BBWO" ) # Points Prep obs_prep(model_id = "bam_v5_can71", species_id = "BBWO") # Raster Prep obs_prep(model_id = "bam_v5_can71", species_id = "BBWO", "raster", rast = r0)r0 <- prep_materials( "spatial_prediction", model_id = "bam_v5_can71", species_id = "BBWO" ) # Points Prep obs_prep(model_id = "bam_v5_can71", species_id = "BBWO") # Raster Prep obs_prep(model_id = "bam_v5_can71", species_id = "BBWO", "raster", rast = r0)
Prepare points from Observation point data
obs_prep_points(obs, ...)obs_prep_points(obs, ...)
obs |
Observation materials |
... |
Unused. |
Sf spatial data frame
o <- prep_materials( "observations", model_id = "bam_v5_can71", species_id = "BBWO" ) p <- obs_prep_points(o)o <- prep_materials( "observations", model_id = "bam_v5_can71", species_id = "BBWO" ) p <- obs_prep_points(o)
Prepare raster from Observation point data
obs_prep_raster(obs, rast, scale = 10, ...)obs_prep_raster(obs, rast, scale = 10, ...)
obs |
Observation materials |
rast |
Spatial predictions raster to get the extent etc. |
scale |
Raster scale. |
... |
Unused. |
SpatRaster
o <- prep_materials( "observations", model_id = "bam_v5_can71", species_id = "BBWO" ) r <- prep_materials( "spatial_prediction", model_id = "bam_v5_can71", species_id = "BBWO" ) p <- obs_prep_raster(o, r)o <- prep_materials( "observations", model_id = "bam_v5_can71", species_id = "BBWO" ) r <- prep_materials( "spatial_prediction", model_id = "bam_v5_can71", species_id = "BBWO" ) p <- obs_prep_raster(o, r)
Creates a vector of Spatial values to use downstream when referencing parent values in followup questions.
parent_vals(v)parent_vals(v)
v |
Character vector of Questions values. |
Character vector of Question values formatted for Shiny Inputs, including only spatial values.
parent_vals(c("Slightly agree", "Very biased", "Moderately biased"))parent_vals(c("Slightly agree", "Very biased", "Moderately biased"))
Prepare Predictor Metadata Data
predictor_metadata_prep(model_id)predictor_metadata_prep(model_id)
model_id |
Character. Model ID |
Data frame
predictor_metadata_prep("bam_v5_can71")predictor_metadata_prep("bam_v5_can71")
Create a Table for Predictor Metadata
predictor_metadata_table(predictor_metadata)predictor_metadata_table(predictor_metadata)
predictor_metadata |
Data frame. Predictor metadata |
A reactable table object
predictor_metadata_prep("bam_v5_can71") |> predictor_metadata_table()predictor_metadata_prep("bam_v5_can71") |> predictor_metadata_table()
Add a Prediction Raster Layer to an existing map
predictor_raster_layer(map, raster = NULL, layers = NULL)predictor_raster_layer(map, raster = NULL, layers = NULL)
map |
Leaflet map. |
raster |
SpatRaster. Raster from which to get |
layers |
Character vector. Layers in SpatRaster to plot. |
Leaflet map
r <- predictor_raster_prep("bam_v5_can71") base_map() |> predictor_raster_layer(r, "mean")r <- predictor_raster_prep("bam_v5_can71") base_map() |> predictor_raster_layer(r, "mean")
Create a Leaflet Map of Predictor Raster Data
predictor_raster_map(predictor_raster, layers = NULL, subunits = NULL)predictor_raster_map(predictor_raster, layers = NULL, subunits = NULL)
predictor_raster |
terra SpatRaster. Predictor information. |
layers |
Character vector. Layers in SpatRaster to plot. |
subunits |
Spatial Data frame. Deployment subunits. |
A leaflet map object
predictor_raster_prep("bam_v5_can71") |> predictor_raster_map( layers = "AHM_1km", # Must be a layer in prepared raster subunits = deployment_subunits_prep("deployment1") )predictor_raster_prep("bam_v5_can71") |> predictor_raster_map( layers = "AHM_1km", # Must be a layer in prepared raster subunits = deployment_subunits_prep("deployment1") )
Prepare Predictor Raster Data
predictor_raster_prep(model_id)predictor_raster_prep(model_id)
model_id |
Character. Model ID |
terra Raster
predictor_raster_prep("bam_v5_can71")predictor_raster_prep("bam_v5_can71")
Prepare Deployments
prep_deployments(deployment_id, deployment_type)prep_deployments(deployment_id, deployment_type)
deployment_id |
Character. Deployment ID |
deployment_type |
Character. Type of data to load ("deployment_questions" or "deployment_subunits") |
Data frame of deployments
prep_deployments("deployment1", "deployment_questions") prep_deployments("deployment1", "deployment_subunits") prep_deployments("deployment2", "deployment_questions")prep_deployments("deployment1", "deployment_questions") prep_deployments("deployment1", "deployment_subunits") prep_deployments("deployment2", "deployment_questions")
Fetch and format submitted evaluations
prep_evaluations(user_id, deployment_id = NULL)prep_evaluations(user_id, deployment_id = NULL)
user_id |
Character. User ID. |
deployment_id |
Character. Deployment ID |
Data frame of evaluation details
prep_evaluations("testuser") # Returns 0 rows if no evaluationsprep_evaluations("testuser") # Returns 0 rows if no evaluations
Generic file prep
prep_files(path, name, ...)prep_files(path, name, ...)
path |
Character. File path to fetch. |
name |
Character. Name of data for messaging |
... |
Named model, species, etc. values. See |
File contents depending on file type (see sdmEvalToolCore::read_file()
Prepare Material Settings
prep_material_settings(component_id, model_id, species_id = NULL)prep_material_settings(component_id, model_id, species_id = NULL)
component_id |
Character. Component ID |
model_id |
Character. Model ID |
species_id |
Character. Species ID |
A list with material settings
prep_material_settings("observations", species_id = "BBWO", model_id = "bam_v5_can71") prep_material_settings("predictor_metadata", model_id = "bam_v5_can71") prep_material_settings("spatial_prediction", species_id = "BBWO", model_id = "bam_v5_can71") prep_material_settings("model_summary", species_id = "BBWO", model_id = "bam_v5_can71") prep_material_settings("model_fit", species_id = "BBWO", model_id = "bam_v5_can71") prep_material_settings("model_metadata", model_id = "bam_v5_can71")prep_material_settings("observations", species_id = "BBWO", model_id = "bam_v5_can71") prep_material_settings("predictor_metadata", model_id = "bam_v5_can71") prep_material_settings("spatial_prediction", species_id = "BBWO", model_id = "bam_v5_can71") prep_material_settings("model_summary", species_id = "BBWO", model_id = "bam_v5_can71") prep_material_settings("model_fit", species_id = "BBWO", model_id = "bam_v5_can71") prep_material_settings("model_metadata", model_id = "bam_v5_can71")
Load material files
prep_materials(component_id, model_id, species_id = NULL)prep_materials(component_id, model_id, species_id = NULL)
component_id |
Character. Component ID |
model_id |
Character. Model ID |
species_id |
Character. Species ID |
Loaded file as an R object, material settings returned as an attribute.
prep_materials("observations", species_id = "BBWO", model_id = "bam_v5_can71") prep_materials("model_metadata", model_id = "bam_v5_can71") prep_materials("predictor_metadata", model_id = "bam_v5_can71") #prep_materials("predictor_raster", model_id = "bam_v5_can71") prep_materials("spatial_prediction", species_id = "BBWO", model_id = "bam_v5_can71") prep_materials("model_summary", species_id = "BBWO", model_id = "bam_v5_can71") prep_materials("model_fit", species_id = "BBWO", model_id = "bam_v5_can71") # Expect Errors # prep_materials("observations", model_id = "", species_id = "") # prep_materials("observations", model_id = "bam_v5_can71", species_id = "")prep_materials("observations", species_id = "BBWO", model_id = "bam_v5_can71") prep_materials("model_metadata", model_id = "bam_v5_can71") prep_materials("predictor_metadata", model_id = "bam_v5_can71") #prep_materials("predictor_raster", model_id = "bam_v5_can71") prep_materials("spatial_prediction", species_id = "BBWO", model_id = "bam_v5_can71") prep_materials("model_summary", species_id = "BBWO", model_id = "bam_v5_can71") prep_materials("model_fit", species_id = "BBWO", model_id = "bam_v5_can71") # Expect Errors # prep_materials("observations", model_id = "", species_id = "") # prep_materials("observations", model_id = "bam_v5_can71", species_id = "")
Reads, combines and prepares questions for use in UIs. model_id and
species_id required to create material_id.
prep_questions( component_id, deployment_id, model_id, species_id, user_id = NULL )prep_questions( component_id, deployment_id, model_id, species_id, user_id = NULL )
component_id |
Character. Component ID |
deployment_id |
Character. Deployment ID |
model_id |
Character. Model ID |
species_id |
Character. Species ID |
user_id |
Character. User ID. |
Data frame of questions
# Return all questions prep_questions("ALL", "deployment1", "bam_v5_can71", "BBWO") # Return component specific questions prep_questions("observations", "deployment1", "bam_v5_can71", "BBWO") prep_questions("model_fit", "deployment1", "bam_v5_can71") prep_questions("model_summary", "deployment1", "bam_v5_can71") prep_questions(c("model_summary", "model_fit"), "deployment1", "bam_v5_can71") prep_questions("predictor_raster", "deployment1", "bam_v5_can71") # Return default questions prep_questions("observations", "deployment_test", "bam_v5_can71", "BBWO") # Follow up questions prep_questions("model_fit", "deployment2", "bam_v5_can71", "BBWO") prep_questions("observations", "deployment1", "bam_v5_can71", "BBWO") # Add evaluations #prep_questions("observations", "deployment1", "bam_v5_can71", "BBWO", "draper") prep_questions("observations", "deployment1", "bam_v5_can71", "BBWO", "testuser") # For the abandon review prep_questions("app", "deployment1", "bam_v5_can71", "BBWO", "testuser")# Return all questions prep_questions("ALL", "deployment1", "bam_v5_can71", "BBWO") # Return component specific questions prep_questions("observations", "deployment1", "bam_v5_can71", "BBWO") prep_questions("model_fit", "deployment1", "bam_v5_can71") prep_questions("model_summary", "deployment1", "bam_v5_can71") prep_questions(c("model_summary", "model_fit"), "deployment1", "bam_v5_can71") prep_questions("predictor_raster", "deployment1", "bam_v5_can71") # Return default questions prep_questions("observations", "deployment_test", "bam_v5_can71", "BBWO") # Follow up questions prep_questions("model_fit", "deployment2", "bam_v5_can71", "BBWO") prep_questions("observations", "deployment1", "bam_v5_can71", "BBWO") # Add evaluations #prep_questions("observations", "deployment1", "bam_v5_can71", "BBWO", "draper") prep_questions("observations", "deployment1", "bam_v5_can71", "BBWO", "testuser") # For the abandon review prep_questions("app", "deployment1", "bam_v5_can71", "BBWO", "testuser")
Takes component, questions data frame, and input list from Shiny app and converts responses (evaluations) to JSON body for saving to the data base.
response_to_json(component_id, questions, input_list)response_to_json(component_id, questions, input_list)
component_id |
Character. Component ID. |
questions |
Data frame. From |
input_list |
List of evaluation inputs. |
q1 <- test_questions("model_fit", "deployment2", "bam_v5_can71", "BBWO") q2 <- test_questions("model_summary", "deployment2", "bam_v5_can71", "BBWO") i1 <- test_input_evals(q1) i2 <- test_input_evals(q2) response_to_json("model_fit", rbind(q1, q2), append(i1, i2))q1 <- test_questions("model_fit", "deployment2", "bam_v5_can71", "BBWO") q2 <- test_questions("model_summary", "deployment2", "bam_v5_can71", "BBWO") i1 <- test_input_evals(q1) i2 <- test_input_evals(q2) response_to_json("model_fit", rbind(q1, q2), append(i1, i2))
Save evaluations
save_evaluations(questions, input_list, user_id)save_evaluations(questions, input_list, user_id)
questions |
Data frame. Data frame of questions; output of
|
input_list |
List. List of Shiny inputs; output of
|
user_id |
Character. User ID. |
q <- prep_questions( "observations", "deployment_test", "bam_v5_can71", "BBWO", "testuser" ) a <- test_input_evals(q) # Create example evaluations save_evaluations(q, a, user_id = "testuser") # Compare # Fetch saved from database q <- prep_questions( "observations", "deployment_test", "bam_v5_can71", "BBWO", "testuser" ) q <- evals_list(q) # Convert to list to compare waldo::compare(a, q)q <- prep_questions( "observations", "deployment_test", "bam_v5_can71", "BBWO", "testuser" ) a <- test_input_evals(q) # Create example evaluations save_evaluations(q, a, user_id = "testuser") # Compare # Fetch saved from database q <- prep_questions( "observations", "deployment_test", "bam_v5_can71", "BBWO", "testuser" ) q <- evals_list(q) # Convert to list to compare waldo::compare(a, q)
Create spinner when loading UI elements
sdm_spinner(ui_element)sdm_spinner(ui_element)
ui_element |
Character. UI element name. |
UI element with spinner.
Theme for bslib
sdm_theme()sdm_theme()
bslib theme
sdm_theme()sdm_theme()
Launch the SDM Evaluation Tool Shiny Application
sdm_tool( lang = "english", options = list(host = "0.0.0.0", port = 7405), tabs = c("overview", "predictions", "observations", "model", "predictors", "summary"), user = NULL, user_db = NULL, ... )sdm_tool( lang = "english", options = list(host = "0.0.0.0", port = 7405), tabs = c("overview", "predictions", "observations", "model", "predictors", "summary"), user = NULL, user_db = NULL, ... )
lang |
Character. Language of app; either |
options |
List. Shiny app options (passed to |
tabs |
Character. List the tabs/pages that the UI should have. |
user |
Character. User id. Placeholder for now, used for testing. |
user_db |
A data frame with credentials data or path to SQLite
database created with |
... |
Other arguments passed to |
A Shiny app object. Launched in browser/viewer if interactive.
sdm_tool()sdm_tool()
No tooltip if text NULL.
sdm_tooltip( tooltip_text, trigger = bsicons::bs_icon("info-circle", title = "Details") )sdm_tooltip( tooltip_text, trigger = bsicons::bs_icon("info-circle", title = "Details") )
tooltip_text |
Character. Text to make into the tooltip contents. |
trigger |
Code. Generally HTML tag lists to attach tooltip to. Defaults to (i) icon. |
bslib tooltip
sdm_tooltip("testing") sdm_tooltip( "testing", shiny::tagList("Hi", bsicons::bs_icon("info-circle", title = "Details")) )sdm_tooltip("testing") sdm_tooltip( "testing", shiny::tagList("Hi", bsicons::bs_icon("info-circle", title = "Details")) )
May not be necessary in the long run...
set_options(...)set_options(...)
... |
Named list of options to set |
list of options currently set
Returns a list of selected spatial areas by question value. Used to show selections on the map when "Show identified area" button associated with spatial questions is clicked.
show_spatial(show_clicked, questions, input)show_spatial(show_clicked, questions, input)
show_clicked |
Button input for "Show identified area" for a specific spatial question. Only contains buttons just clicked. |
questions |
Data frame of original questions. |
input |
Input. |
Named list of Question values and spatial subunits for each.
# Example from test_page_summary() c <- "deployment_subunits" d <- "deployment1" m <- "bam_v5_can71" s <- "BBWO" o <- 2 v <- "Confident" sp <- paste(d, m, s, c, o, 0, sep = "_") input <- list(c(4,5,9)) names(input) <- paste0(sp, "-", v) clicked <- paste0(sp, "-show") questions <- test_questions(c, d, m, s) show_spatial(clicked, questions, input) # Example from test_page_preditions() c <- "spatial_prediction" d <- "deployment1" m <- "bam_v5_can71" s <- "BBWO" o <- 1 v <- c("Severe_over", "Moderate_over", "Accurate", "Moderate_under", "Severe_under", "Unknown") sp <- paste(d, m, s, c, o, 0, sep = "_") input <- list(c(4,5,9), NULL, NULL, c(3,5,10), NULL, NULL) names(input) <- paste0(sp, "-", v) clicked <- paste0(sp, "-show") questions <- test_questions(c, d, m, s) show_spatial(clicked, questions, input)# Example from test_page_summary() c <- "deployment_subunits" d <- "deployment1" m <- "bam_v5_can71" s <- "BBWO" o <- 2 v <- "Confident" sp <- paste(d, m, s, c, o, 0, sep = "_") input <- list(c(4,5,9)) names(input) <- paste0(sp, "-", v) clicked <- paste0(sp, "-show") questions <- test_questions(c, d, m, s) show_spatial(clicked, questions, input) # Example from test_page_preditions() c <- "spatial_prediction" d <- "deployment1" m <- "bam_v5_can71" s <- "BBWO" o <- 1 v <- c("Severe_over", "Moderate_over", "Accurate", "Moderate_under", "Severe_under", "Unknown") sp <- paste(d, m, s, c, o, 0, sep = "_") input <- list(c(4,5,9), NULL, NULL, c(3,5,10), NULL, NULL) names(input) <- paste0(sp, "-", v) clicked <- paste0(sp, "-show") questions <- test_questions(c, d, m, s) show_spatial(clicked, questions, input)
Skip testthat tests if no data is detected
skip_if_no_data()skip_if_no_data()
Logical
Create a Leaflet Map of Spatial Prediction Data
spatial_prediction_map(spatial_prediction, subunits = NULL, ns = identity)spatial_prediction_map(spatial_prediction, subunits = NULL, ns = identity)
spatial_prediction |
terra Raster. Spatial predictions |
subunits |
Spatial Data frame. Deployment subunits. |
ns |
Namespace. |
A leaflet map object
p <- spatial_prediction_prep(model_id = "bam_v5_can71", species_id = "BBWO") s <- deployment_subunits_prep("deployment1") spatial_prediction_map(p) spatial_prediction_map(p, s)p <- spatial_prediction_prep(model_id = "bam_v5_can71", species_id = "BBWO") s <- deployment_subunits_prep("deployment1") spatial_prediction_map(p) spatial_prediction_map(p, s)
Prepare Spatial Prediction Data
spatial_prediction_prep(model_id, species_id)spatial_prediction_prep(model_id, species_id)
model_id |
Character. Model ID |
species_id |
Character. Model ID |
terra Raster
spatial_prediction_prep(model_id = "bam_v5_can71", species_id = "BBWO")spatial_prediction_prep(model_id = "bam_v5_can71", species_id = "BBWO")
Prepare Template Data
template_prep(model_id, species_id)template_prep(model_id, species_id)
model_id |
Character. Model ID |
species_id |
Character. Species ID |
Data frame
template_prep(model_ = "bam_v5_can71", species_id = "BBWO")template_prep(model_ = "bam_v5_can71", species_id = "BBWO")
Create a Leaflet Map of Template Spatial Data
template_spatial_map(template_spatial, subunits = NULL, ns = identity)template_spatial_map(template_spatial, subunits = NULL, ns = identity)
template_spatial |
terra Raster. Template spatial data |
subunits |
Spatial Data frame. Deployment subunits. |
ns |
Namespace. |
A leaflet map object
p <- template_spatial_prep(model_id = "bam_v5_can71", species_id = "BBWO") s <- deployment_subunits_prep("deployment1") template_spatial_map(p) template_spatial_map(p, s)p <- template_spatial_prep(model_id = "bam_v5_can71", species_id = "BBWO") s <- deployment_subunits_prep("deployment1") template_spatial_map(p) template_spatial_map(p, s)
Prepare Template Spatial Data
template_spatial_prep(model_id, species_id)template_spatial_prep(model_id, species_id)
model_id |
Character. Model ID |
species_id |
Character. Model ID |
terra Raster
template_spatial_prep(model_id = "bam_v5_can71", species_id = "BBWO")template_spatial_prep(model_id = "bam_v5_can71", species_id = "BBWO")
Create a Table for Template Data
template_table(template)template_table(template)
template |
Data frame with template information |
Reactable table
template_prep(model_id = "bam_v5_can71", species_id = "BBWO") |> template_table()template_prep(model_id = "bam_v5_can71", species_id = "BBWO") |> template_table()
Not all arguments are used by all modules.
test_comp( module, use = c("parent_id", "deployment_id", "model_id", "species_id", "spatial_ids", "spatial_selection", "map_views"), deployment_id = "deployment1", model_id = "bam_v5_can71", species_id = "BBWO", spatial_ids = NULL, spatial_selection = list(show_clicked = NULL, show_spatial_ids = NULL), map_views = list(active_tab = NULL, set_by = NULL, view = NULL) )test_comp( module, use = c("parent_id", "deployment_id", "model_id", "species_id", "spatial_ids", "spatial_selection", "map_views"), deployment_id = "deployment1", model_id = "bam_v5_can71", species_id = "BBWO", spatial_ids = NULL, spatial_selection = list(show_clicked = NULL, show_spatial_ids = NULL), map_views = list(active_tab = NULL, set_by = NULL, view = NULL) )
module |
Character. Module Name. |
use |
Character vector. Objects to include |
deployment_id |
Character. Example Deployment ID. |
model_id |
Character. Example Model ID. |
species_id |
Character. Example Species ID. |
spatial_ids |
Character. Optional starting spatial ids. |
spatial_selection |
List. Optional starting spatial selection
( |
map_views |
List. Optional set map views for map synchronization. |
Shiny App
Test the Deployment Subunits Component
test_comp_deployment_subunits(...)test_comp_deployment_subunits(...)
... |
Arguments passed to other functions. |
A Shiny app object
test_comp_deployment_subunits()test_comp_deployment_subunits()
Test the Model Fit Component
test_comp_model_fit(...)test_comp_model_fit(...)
... |
Arguments passed to other functions. |
A Shiny app object
test_comp_model_fit()test_comp_model_fit()
Test the Model Summary Component
test_comp_model_summary(...)test_comp_model_summary(...)
... |
Arguments passed to other functions. |
A Shiny app object
test_comp_model_summary()test_comp_model_summary()
Test the Observations Chart Component
test_comp_obs_chart(...)test_comp_obs_chart(...)
... |
Arguments passed to other functions. |
A Shiny app object
test_comp_obs_chart()test_comp_obs_chart()
Test the Observations Component
test_comp_observations(...)test_comp_observations(...)
... |
Arguments passed to other functions. |
A Shiny app object
test_comp_observations()test_comp_observations()
Test the Predictor Metadata Component
test_comp_predictor_metadata(...)test_comp_predictor_metadata(...)
... |
Arguments passed to other functions. |
A Shiny app object
test_comp_predictor_metadata()test_comp_predictor_metadata()
Test the Predictor Raster Component
test_comp_predictor_raster(...)test_comp_predictor_raster(...)
... |
Other arguments. |
A Shiny app object
test_comp_predictor_raster()test_comp_predictor_raster()
Test the Spatial Prediction Component
test_comp_spatial_prediction(...)test_comp_spatial_prediction(...)
... |
Arguments passed to other functions. |
A Shiny app object
test_comp_spatial_prediction()test_comp_spatial_prediction()
Test the Template Component
test_comp_template(...)test_comp_template(...)
... |
Arguments passed to other functions. |
A Shiny app object
test_comp_template()test_comp_template()
Test the Template Spatial Component
test_comp_template_spatial(...)test_comp_template_spatial(...)
... |
Arguments passed to other functions. |
A Shiny app object
test_comp_template_spatial()test_comp_template_spatial()
This can be used for testing loading/extracting/counting/etc. questions. These are created by running the App, saving data, and then extracting the JSON bodies. They can be updated the same way. Note that there are different bodies to test different kinds of behaviour.
test_evaluation_body(component_id = "observations")test_evaluation_body(component_id = "observations")
component_id |
Character. Id of the test evaluation body to use. Currently "observations", "model_fit_a", or "model_fit_b" |
Character. JSON string for hypothetical evaluation
test_evaluation_body() ## Not run: # After created through app with 'testuser' and `deployment2` retrieved with: db_read_evaluations(db_connect_check(), "deployment2", "testuser") |> dplyr::filter(component_id == "model_fit") |> dplyr::slice(1) |> dplyr::pull(evaluation_body) ## End(Not run)test_evaluation_body() ## Not run: # After created through app with 'testuser' and `deployment2` retrieved with: db_read_evaluations(db_connect_check(), "deployment2", "testuser") |> dplyr::filter(component_id == "model_fit") |> dplyr::slice(1) |> dplyr::pull(evaluation_body) ## End(Not run)
Create dummy input values for evaluations
test_input_evals(questions)test_input_evals(questions)
questions |
Data frame. Output of |
List of dummy input values. Mimics and input object from the Shiny
app.
q <- test_questions() test_input_evals(q)q <- test_questions() test_input_evals(q)
Not all arguments are used by all modules.
test_page( module, deployment_id = "deployment1", model_id = "bam_v5_can71", species_id = "BBWO", user_id = "testuser", user_role = "evaluator", user_admin = FALSE, map_views = list(active_tab = NULL, set_by = NULL, view = NULL) )test_page( module, deployment_id = "deployment1", model_id = "bam_v5_can71", species_id = "BBWO", user_id = "testuser", user_role = "evaluator", user_admin = FALSE, map_views = list(active_tab = NULL, set_by = NULL, view = NULL) )
module |
Character. Module Name. |
deployment_id |
Character. Example Deployment ID. |
model_id |
Character. Example Model ID. |
species_id |
Character. Example Species ID. |
user_id |
Character. Example User ID. |
user_role |
Character. Example User Role. |
user_admin |
Logical. Example User Admin status. |
map_views |
List. Optional set map views for map synchronization. |
Shiny App
Create dummy sf point data
test_points()test_points()
sf data frame
test_points()test_points()
Create dummy questions for testing
test_questions( component = "observations", deployment_id = "deployment_test", model_id = "bam_v5_can71", species_id = "BBWO", types = c("spatial", "ordinal", "simple_text"), user_id = "testuser" )test_questions( component = "observations", deployment_id = "deployment_test", model_id = "bam_v5_can71", species_id = "BBWO", types = c("spatial", "ordinal", "simple_text"), user_id = "testuser" )
component |
Component. |
deployment_id |
Deployment ID. |
model_id |
Model ID. |
species_id |
Species ID. |
types |
Question types. |
user_id |
User id. |
test_questions()test_questions()
Create dummy terra SpatRaster data
test_raster()test_raster()
SpatRaster
test_raster()test_raster()
Create tooltip from material settings
tt_material_settings(material)tt_material_settings(material)
material |
R Object depending on the type of material loaded. May have attributes such as 'material_settings'. |
bslib tooltip output from sdm_tooltip().
Create dynamic question inputs in the server using the prepared questions data frame.
ui_questions(questions, spatial_ids = NULL, width = NULL)ui_questions(questions, spatial_ids = NULL, width = NULL)
questions |
Data frame prepared by |
spatial_ids |
Character vector. [NOT CURRENTLY USED, see
|
width |
Numeric. Optional width of Shiny UI input. |
Shiny tagList of UI elements
q <- prep_questions( "observations", "deployment1", "bam_v5_can71", "BBWO", user_id = "testuser" ) ui_questions(q) # More than one component q <- prep_questions( c("model_fit", "model_summary"), "deployment2", "bam_v5_can71", "BBWO", user_id = "testuser" ) u <- ui_questions(q)q <- prep_questions( "observations", "deployment1", "bam_v5_can71", "BBWO", user_id = "testuser" ) ui_questions(q) # More than one component q <- prep_questions( c("model_fit", "model_summary"), "deployment2", "bam_v5_can71", "BBWO", user_id = "testuser" ) u <- ui_questions(q)
Because there many be many possible selections for Spatial inputs, we use
Serve-side processing to speed things up. This means that we initialize the
Spatial input, and then we have to update it with the spatial input options
(i.e. the list of spatial ids in the drop down menu). This function performs
that update when the ids are ready (see the use of ui_questions_update() in
mod_utils_evaluations_server().
ui_questions_update(questions, spatial_ids = NULL)ui_questions_update(questions, spatial_ids = NULL)
questions |
Data frame prepared by |
spatial_ids |
Character vector. [NOT CURRENTLY USED, see
|
Nothing. Performs Javascript update (see shiny::updateSelectizeInput()).
Validate input ids
validate_ids(...)validate_ids(...)
... |
Named arguments containing id values to validate (e.g., deployment_id, model_id, species_id) |
NULL (invisibly), or throws validation error if any id is missing
Helper function to format Question values as Shiny Input names
value_to_input(v)value_to_input(v)
v |
Character vector of Question values. |
Character string of values formatted for Shiny Inputs
value_to_input("Strongly Agree")value_to_input("Strongly Agree")