Using spdgt.core with spdgt.sight
Source:vignettes/spdgt-sight-integration.Rmd
spdgt-sight-integration.Rmdspdgt.core provides reference data lookups that feed directly into spdgt.sight, SpeedGoat’s package for sightability survey data and analysis. This vignette shows the typical workflow: discovering reference data with spdgt.core, then using it in spdgt.sight.
Setup
Both packages authenticate through spdgt.auth. Loading either package triggers the login flow if needed.
library(spdgt.core)
library(spdgt.sight)Discovering your data
Before querying survey data, you need to know your species, analysis units, and survey types. spdgt.core lookups make this easy.
Species
Start by listing the species configured for your project:
Pick the one you want to work with:
sp_id <- lkup_species_id("Mule Deer")
sp_id
#> [1] 1Analysis units and management units
DAUs (analysis units) and GMUs (management units) are species-specific. View what’s available:
Survey types
Survey types are also species-specific:
lkup_survey_type(species_id = sp_id)
st_id <- lkup_survey_type_id("Sightability", species_id = sp_id)
st_id
#> [1] 9Querying survey data
With IDs in hand, use spdgt.sight to query survey data. spdgt.sight functions accept names directly (they use spdgt.core under the hood), but using IDs avoids repeated lookups when making multiple calls.
Listing surveys
surveys <- sight_read_surveys(
species = "Mule Deer",
survey_type = "Sightability"
)
surveysFitting a sightability model
sight_fit_model() runs the model and returns population
estimates:
estimates <- sight_fit_model(
species = "Mule Deer",
spatial_focus = "DAU",
bio_year = 2024,
analysis_unit = "Area 1",
survey_type = "Sightability",
model = "Mule Deer"
)
estimatesFor a richer summary including data diagnostics:
summary <- sight_fit_summary(
species = "Mule Deer",
spatial_focus = "DAU",
bio_year = 2024,
analysis_unit = "Area 1",
survey_type = "Sightability",
model = "Mule Deer"
)Building Shiny dropdowns
spdgt.core _opts functions return named integer vectors
designed for shiny::selectInput(). This makes it easy to
build interactive UIs backed by spdgt.sight:
# In a Shiny UI
selectInput("species", "Species", choices = lkup_species_opts())
# Once a species is selected, populate dependent dropdowns
selectInput("dau", "Analysis unit",
choices = lkup_dau_opts(species_id = input$species)
)
selectInput("survey_type", "Survey type",
choices = lkup_survey_type_opts(species_id = input$species)
)
selectInput("strata", "Strata",
choices = lkup_strata_opts(
species_id = input$species,
survey_type_id = input$survey_type
)
)These reactive dropdowns cascade: selecting a species populates the available DAUs, survey types, and strata automatically.