vignettes/how_to_mhealthannotator.Rmd
how_to_mhealthannotator.Rmd
devtools::install_github("Sage-Bionetworks/mhealthannotator")
Many functions in mhealthannotator use reticulate and the Synapse Python client. See the reticulate documentation for information on how to set R to use a specific version of Python if you don’t want to use the default Python installation on your machine. Whichever Python installation you choose should have synapseclient installed.Because mhealthannotator uses reticulate, it is not compatible with the synapser package.
Documentation for installation can be found here
To create a visualization function, expected input is any parse-able data json, jpeg etc. And output will a filepath to the processed files.
## a good and simple example is to make a function that takes in filepath
## and convert to jpeg if image is png format
visualize_photo <- function(filepath){
if(tools::file_ext(filepath) == "png"){
new_filepath <- sub('\\.png$', '.jpg', filepath)
png_mat <- png::readPNG(filepath)
jpeg::writeJPEG(png_mat, target = new_filepath, quality = 1)
file.remove(filepath)
return(new_filepath)
}else{
return(filepath)
}
}
To create a config file, the app will accept config.yml files containing key-values pair. The code chunk below can be used as a template for reference.
# template to use for config file
default:
app_url: 'https://shinypro.synapse.org/users/atediarjo/mhealthannotator-oauth/'
team_id: '3425336'
synapse_opts:
output_parent_id:
- "syn25614357"
synapse_tbl_id:
- "syn22281748"
output_filename:
- "psoriasis_plaque_annotations.tsv"
filehandle_cols:
- "psoriasisAreaPhoto.jpg"
- "psoriasisAreaPhoto.png"
uid:
- "recordId" # unique identifier for that file in synapse table
n_batch: 5
keep_metadata:
- "participantId"
- "createdOn"
sort_keys:
- "recordId" # optional
survey_opts:
survey_1:
colname: "PGA"
type: "radio"
prompt: "PGA:"
input_choices:
0: 0
1: 1
2: 2
3: 3
4: 4
Cannot Tell: "Cannot Tell"
survey_2:
colname: "erythema"
type: "checkbox_group"
prompt: "Erythema:"
input_choices:
0: 0
1: 1
2: 2
3: 3
4: 4
Cannot Tell: "Cannot Tell"
survey_3:
colname: "induration"
type: "slider"
prompt: "Induration:"
input_choices:
min: 0
max: 5
step: 1
survey_4:
colname: "scaling"
type: "slider"
prompt: "Scaling:"
input_choices:
min: 0
max: 5
step: 1
image_opts:
width: "auto"
height: "auto"
To run the app, you will only require two parameters, which is the configurations file and your desired function.
You can refer to Schema Configuration to customize each of the parameter of the configuration file. To check whether you are using the correct and available parameters you can run mhealthannotator::validate_config_file(<path_to_config>)
.
Afterwards, you will be able to run the app by invoking:
mhealthannotator::run_app(config = "config.yml",
funs = visualize_photo)
To choose config options other than default
, you can run:
before running the app. More documentation here