This is an example shiny dashboard used for monitoring Ocean Use Survey results from SeaSketch. The data contained in this repo were entirely fabricated for demonstration purposes.
This app is designed to be both a functional example and a template that can be adapted to monitor other, real SeaSketch surveys. The goal was to generalize as much of the code as possible, allowing users to make minimal changes to apply it to their unique survey. That being said, surveys in SeaSketch can vary widely, and the amount of work required to adapt it to a given survey will also vary.
These are the basic steps required to adapt this framework to your survey
- Clone the repo
- Replace
data/responses.csv
anddata/shapes.json
with the respective survey exports from your SeaSketch project- Note that the spatial data from SeaSketch will defualt to a different name - change the file name to
shapes.json
- Note that the spatial data from SeaSketch will defualt to a different name - change the file name to
- Replace
data/eez.fgb
with a flatgeobuf containing the EEZ or other study area polygon applicable to your project - Add
data/survey_targets.csv
with your own targets CSV containing the columns "sector" and "target" - Edit
R/project_variables.R
- this script contains all project-specific variables:project
is the prefix added to all downloads from the appapp_title
will be diplayed in the upper left hand corner of the app uiseasketch_url
should be the link to your seasketch project page and is accessible via the "Responses Updated:" box on the "Overview" tabsectors
is a character vector of ocean use sectors in your projectregion
is the export id of your region questionregion_list
is a character vector of the regions respondents can chooseage_groups
is a character vector of the age groups respondents can choose fromgenders
is a character vector of the genders respondents can choose fromjson_columns
is a dataframe containing the export ids of any group response questions (which export as JSON-formatted strings), and their respective answer option objects (age_groups
andgenders
in this example) - this excludesregion
because it is parsed differently from the other group response questionscolumns_to_remove
is a character vector of any columns you don't need in your cleaned datashape_attributes_to_keep
is a character vector of shape attributes you want to keep in your cleaned spatial data
- Run
R/data_init.R
- this will process the data inresponses.csv
andshapes.json
, writing five*.RDS
files todata/temp
:respondent_info.RDS
contains aggregated response data, with one row per survey response (similar to how it's exported from SeaSketch)responses.RDS
contains response data with one row per sector responseshapes.RDS
contains the spatial data joined with other response data in the form of anSF
dataframedata_date.RDS
contains the date thatresponses.csv
was createdtemp_data_date.RDS
contains the date that the files indata/temp
were created (i.e. whenR/data_init.R
was run)
- Secure app
- If your app doesn't require authentication, skip to the last bullet in this section - otherwise, follow the steps below
- Create user database
- Source
auth/create_user_db.R
- Run
create_user_db({initial_user}, {password}, {passphrase})
with the arguments:initial_user
: your desired username to access the apppassword
: your desired passwordpassphrase
your desired passphrase to decrypt the database
- This will create
auth/users.sqlite
- This app implementation stores the passphrase in a (gitignored) plaintext file
auth/passphrase.txt
which is read inglobal.R
- consider whether this is secure enough for your needs - Once the app is up and running you can use initial credentials created with
create_user_db()
to login and any additional users can be added from the shinymanager admin interface accessible via the plus icon in the lower righthand corner of the app
- Source
- Add
R/secure_option.R
which should assignTRUE
to the variablesecure
- this is intended to be an easy gitignored way to develop locally withsecure
set toFALSE
. Just make sure it's set toTRUE
wherever it's deployed. If you don't need your app secured, just setsecure
toFALSE
and call it a day
Currently, SeaSketch doesn't have a developer API for requesting survey data. Updates will need to be done by manually adding the latest responses.csv
and shapes.json
files exported from SeaSketch to the shiny app repo.