Skip to content

Commit

Permalink
Merge pull request #208 from GEO-BON/error_message
Browse files Browse the repository at this point in the history
Error message and output one-by-one implementation example
  • Loading branch information
JoryGriffith authored Dec 17, 2024
2 parents 332f4aa + 8bd037a commit 963987f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
46 changes: 22 additions & 24 deletions scripts/helloWorld/helloR.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# Script location can be used to access other scripts
print(Sys.getenv("SCRIPT_LOCATION"))

## Install required packages
packages <- c("rjson")
new.packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
## Install required packages that are not available on Anaconda
#packages <- c("someRarePackage")
#new.packages <- packages[!(packages %in% installed.packages()[,"Package"])]
#if(length(new.packages)) install.packages(new.packages)

library("rjson")
input <- fromJSON(file=file.path(outputFolder, "input.json"))
# Reading inputs
input <- biab_inputs()
print("Inputs: ")
print(input)

Expand All @@ -17,16 +17,22 @@ example_jpg = file.path(outputFolder, "example.jpg")
if(!file.exists(example_jpg)) {
download.file("https://geobon.org/wp-content/uploads/2018/01/default-image.png", example_jpg, "auto")
}
biab_output("some_picture", example_jpg)

example_tiff = file.path(outputFolder, "utmsmall.tif")
if(!file.exists(example_tiff)) {
download.file("https://github.com/yeesian/ArchGDALDatasets/raw/master/data/utmsmall.tif", example_tiff, "auto")
}
biab_output("heat_map", example_tiff)

# Uncomment this to stop the script here with an error message
#biab_error_stop("Some error")

example_json = file.path(outputFolder, "sample.json")
if(!file.exists(example_json)) {
download.file("https://gist.githubusercontent.com/wavded/1200773/raw/e122cf709898c09758aecfef349964a8d73a83f3/sample.json", example_json, "auto")
}
biab_output("geo_json", example_json)

some_csv_data = file.path(outputFolder, "some_data.csv")
write("Model,mpg,cyl,disp,hp,drat,wt,qsec,vs,am,gear,carb
Expand All @@ -35,6 +41,7 @@ Mazda RX4 Wag,21,6,160,110,3.9,2.875,17.02,0,1,4,4
Datsun 710,22.8,4,108,93,3.85,2.32,18.61,1,1,4,1
Hornet 4 Drive,21.4,6,258,110,3.08,3.215,19.44,1,0,3,1
", some_csv_data)
biab_output("some_csv_data", some_csv_data)

# Example from https://en.wikipedia.org/wiki/Tab-separated_values
some_tsv_data = file.path(outputFolder, "some_data.tsv")
Expand All @@ -45,31 +52,22 @@ write("Sepal length Sepal width Petal length Petal width Species
4.6 3.1 1.5 0.2 I. setosa
5.0 3.6 1.4 0.2 I. setosa
", some_tsv_data)
biab_output("some_tsv_data", some_tsv_data)

# Example from https://en.wikipedia.org/wiki/Tab-separated_values
some_html_output = file.path(outputFolder, "some_page.html")
write(
"<h1>This is a page</h1><p>With a fancy interactive graph or the like.</p>",
some_html_output
)
biab_output("some_html_output", some_html_output)

## Outputing result to JSON
# notice that the warning string is not part of the yml spec, so it cannot be used by other scripts, but will still be displayed.
output <- list(#"error" = "Some error", # Use error key to stop the rest of the pipeline
"info" = "Some information message",
"warning" = "Some warning",
"text" = "This is just an example. In case you have a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long text it will need to be unfolded to see it all.",
"number" = input$intensity * 3,
"heat_map" = example_tiff,
"geo_json" = example_json,
"some_csv_data" = some_csv_data,
"some_tsv_data" = some_tsv_data,
"some_html_output" = some_html_output,
"some_picture" = example_jpg,
"userdata_available" = list.files(file.path(Sys.getenv("USERDATA_LOCATION"))),
"undocumented_output" = "Some debug output")
biab_info("Some information message")
biab_warning("Some warning")

jsonData <- toJSON(output, indent=2)
write(jsonData, file.path(outputFolder,"output.json"))
biab_output("text", "This is just an example. In case you have a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long text it will need to be unfolded to see it all.")
biab_output("number", input$intensity * 3)
biab_output("userdata_available", list.files(file.path(Sys.getenv("USERDATA_LOCATION"))))
biab_output("undocumented_output", "Some debug output")

# (If we get a problem with encoding, we could use utf-8 library to clean the output, since the server reads it as utf-8)
# (If there is a problem with encoding, one could use utf-8 library to clean the output, since the server reads it as utf-8)
17 changes: 12 additions & 5 deletions scripts/helloWorld/helloR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ inputs:
- second option
- third option
- fourth option
- fifth options
- sixth options
- seventh option
- eight option
- ninth option
- tenth option
- eleventh option
example:
- third option
- fourth option
- first option
- eleventh option
freeflow_text:
label: Freeflow text
description: This is regular text, and can have multiple lines.
Expand Down Expand Up @@ -108,7 +115,7 @@ outputs:
type: text/html
example: /path/to/some/example.html
references:
- text: John Doe, The ins and outs of copy-pasting, BioScience, Volume 71, Issue 5, May 2021, Pages 448–451
doi: 10.1093/biosci/biab041
- text: John Doe, The ins and outs of copy-pasting, CopyScience, Volume 71, Issue 5, May 2021, Pages 448–451
doi: 10.1093/copysci/biab041
- text: Nick Copy, Rupert Paste, Replicating text in a documentation context, Textopasto, 405, (123456), (2022).
doi: 10.1016/j.biab.2021.115424
doi: 10.1016/j.tpasto.2021.115424

0 comments on commit 963987f

Please sign in to comment.