Title: | Turing Geovisualization Engine R package |
---|---|
Description: | Turing Geovisualization Engine R package for geospatial visualization and analysis. |
Authors: | Layik Hama [aut, cre] , Lydia France [aut], Nick Barlow [aut], Roly Perera [aut], Roger Beecham [aut] , Nik Lomax [aut] |
Maintainer: | Layik Hama <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.0 |
Built: | 2024-11-12 06:13:36 UTC |
Source: | https://github.com/tgve/tgver |
Internal helper function to run a 'plumber' instance on specific host and port.
background_run(server, port = 8000, host = "127.0.0.1")
background_run(server, port = 8000, host = "127.0.0.1")
server |
an instance of 'plumber' class |
port |
numeric port to pass to 'server' instance |
host |
character host value for 'server' instance |
Internal helper function to: 1. copy the bundled zip 2. unzip 3. cleanup as required. TODO: return a value?
copy_tgve(path, over.write = TRUE)
copy_tgve(path, over.write = TRUE)
path |
character path of TGVE instance |
over.write |
boolean whether to cleanup the instance in 'path' |
Current version only tries to: Find two files, one .csv and the other .geojson and pass them to TGVE as 'defaultURL' and 'geographyURL' respectively. It will also look at their column names and try to find matching columns. If there is one file, it passes it to 'explore_file' function.
explore_dir(path, background = FALSE)
explore_dir(path, background = FALSE)
path |
character of a data directory. |
background |
logical value whether to run instance in 'callr'. |
no value returned, depending on 'background' either a or not blocking 'plumber::pr' instance is started. A message is displayed with instance details.
{ p = file.path(tempdir(), "data") dir.create(p) gURL = paste0("https://raw.githubusercontent.com/saferactive/", "tgve/main/pf-only-name.geojson") dURL = "https://raw.githubusercontent.com/saferactive/tgve/main/ksi-pf.csv" download.file(gURL, destfile = file.path(p, "pf.geojson")) download.file(dURL, destfile = file.path(p, "data.csv")) ps = explore_dir(p, background = TRUE) ps$kill() unlink(p, recursive = TRUE) }
{ p = file.path(tempdir(), "data") dir.create(p) gURL = paste0("https://raw.githubusercontent.com/saferactive/", "tgve/main/pf-only-name.geojson") dURL = "https://raw.githubusercontent.com/saferactive/tgve/main/ksi-pf.csv" download.file(gURL, destfile = file.path(p, "pf.geojson")) download.file(dURL, destfile = file.path(p, "data.csv")) ps = explore_dir(p, background = TRUE) ps$kill() unlink(p, recursive = TRUE) }
Current version can only read geojson/csv files using the given 'file.uri'.
explore_file(file.uri, background = FALSE)
explore_file(file.uri, background = FALSE)
file.uri |
character path of file to explore |
background |
Boolean to run the process in the background, defaults to 'FALSE' |
no value returned, depending on 'background' either a or not blocking 'plumber' instance is started. A message is displayed with instance details.
{ fp = file.path(tempdir(), "test.geojson") gj = c( '[ {"type":"Point","coordinates":[0,0]}, {"type":"LineString","coordinates":[[-1,-1],[1,1]]}, { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {"id":1}, "geometry": {"type": "Point", "coordinates": [100.0, 0.0]} } ] } ]' ) write(gj, fp) ps = tgver::explore_file(fp, background = TRUE) ps$kill() unlink(fp, recursive = TRUE) }
{ fp = file.path(tempdir(), "test.geojson") gj = c( '[ {"type":"Point","coordinates":[0,0]}, {"type":"LineString","coordinates":[[-1,-1],[1,1]]}, { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {"id":1}, "geometry": {"type": "Point", "coordinates": [100.0, 0.0]} } ] } ]' ) write(gj, fp) ps = tgver::explore_file(fp, background = TRUE) ps$kill() unlink(fp, recursive = TRUE) }
Explore an sf R object using TGVE npm package.
explore_sf( sf = NULL, background = FALSE, static = FALSE, path = tempInstance() )
explore_sf( sf = NULL, background = FALSE, static = FALSE, path = tempInstance() )
sf |
a valid sf object that can be converted to geojson |
background |
Boolean to decide whether plumber |
static |
boolean to decide whether data is written to disk and self contained application is built |
path |
path of a TGVE instance, defaults to one in 'tempdir()' should run in the background |
depending on 'background' either a or not blocking 'plumber::pr' object is started or returned. In the case of a 'backgruond' FALSE value a message is displayed with object details.
{ gj = c( '[ {"type":"Point","coordinates":[0,0]}, {"type":"LineString","coordinates":[[-1,-1],[1,1]]}, { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {"id":1}, "geometry": {"type": "Point", "coordinates": [100.0, 0.0]} } ] } ]' ) sf = geojsonsf::geojson_sf(gj) ps = tgver::explore_sf(sf, background = TRUE) ps$kill() }
{ gj = c( '[ {"type":"Point","coordinates":[0,0]}, {"type":"LineString","coordinates":[[-1,-1],[1,1]]}, { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {"id":1}, "geometry": {"type": "Point", "coordinates": [100.0, 0.0]} } ] } ]' ) sf = geojsonsf::geojson_sf(gj) ps = tgver::explore_sf(sf, background = TRUE) ps$kill() }
Function to replace patterns in given files.
file_replace(files = NULL, pattern, replacement)
file_replace(files = NULL, pattern, replacement)
files |
character vector of full paths where pattern to be replaced. |
pattern |
character pattern to replace using 'gsub'. |
replacement |
character to replace pattern with using 'gsub'. |
The function can generate a URL based on a base URL and as many as TGVE API variables provided to the function.
get_url(base = "http://127.0.0.1:8000", ...)
get_url(base = "http://127.0.0.1:8000", ...)
base |
character URL defaults to 'http://127.0.0.1:8000' |
... |
any or all of the TGVE API variables to replace/add values to. |
character URL generated from 'base' and 'tgver::'
{ url = get_url(dark="false") url == "http://127.0.0.1:8000?dark=false" url url = get_url() url }
{ url = get_url(dark="false") url == "http://127.0.0.1:8000?dark=false" url url = get_url() url }
Function to explore available API variables, their types and examples of using them in the TGVE
help()
help()
no object is returned
{ help() }
{ help() }
The task of checking a URL is "hard", see this by J. Hester: https://cran.r-project.org/web/packages/rex/vignettes/url_parsing.html To avoid having a dependency for now, let us not use "rex" R package. To try and understand the regex please see this gist which includes a breakdown of the regex: https://gist.github.com/dperini/729294
is_valid_url(string)
is_valid_url(string)
string |
must be valid vector of URLs |
Function to find what files may contain TGVE API variables for functions like 'file_replace' to consume.
list_api_files(path = NULL)
list_api_files(path = NULL)
path |
where TGVE instance is located. |
Internal helper function to "browse" a URL.
openURL( url = NULL, host = "127.0.0.1", port = 8000, browser = FALSE, path = "", protocol = "http://" )
openURL( url = NULL, host = "127.0.0.1", port = 8000, browser = FALSE, path = "", protocol = "http://" )
url |
character url, if given and valid other parameters will be ignored. |
host |
character host to pass to plumber |
port |
integer port to pass to plumber |
browser |
Boolean whether to specifically launch a browser |
path |
character path to TGVE instance |
protocol |
character protocol, this may change |
This function initializes an instance of TGVE for permanent use compared with what tgve_server which relies on a 'tempdir' based instance. It requires a path.
setup(path = NULL, create = TRUE)
setup(path = NULL, create = TRUE)
path |
Character URI to copy tgve instance in. |
create |
Boolean to create new directory at path, defaults to 'TRUE'. |
no value returned
{ p = file.path(tempdir(), "tgve") setup(p) }
{ p = file.path(tempdir(), "tgve") setup(p) }
copy the inst/tgve to a temp in an R session
tempInstance()
tempInstance()
This is the main and most basic function to run an instance of TGVE without back-end. Compared to tgve_server, this function only uses internal functions to setup an instance then opens the entry HTML file. If a path of an instance is provided it opens it, otherwise creates an instance from a 'tempdir'.
tgve( path = Sys.getenv("TEMP_path_ENV"), browse = TRUE, remote = FALSE, url = "https://tgve.github.io/app/" )
tgve( path = Sys.getenv("TEMP_path_ENV"), browse = TRUE, remote = FALSE, url = "https://tgve.github.io/app/" )
path |
character directory of a current instance to browse. Defaults to 'TEMP_PATH_ENV' environment variable. |
browse |
boolean to decide whether to browse the instance or not. |
remote |
boolean whether to run a remote instance of TGVE. If TRUE the above 'path' and 'browse' parameters will be ignored. Defaults to 'FALSE' |
url |
if 'remote' is true, then this will be used as the parameter to pass to internal function 'openURL'. It defaults, for convenience, to 'https://tgve.github.io/app/' instance. |
directory of the new instance if 'path' is not provided.
tgve() # just get the path of the HTML p = tgve(browse = FALSE) file.exists(p)
tgve() # just get the path of the HTML p = tgve(browse = FALSE) file.exists(p)
The function accepts a 'path' to get a directory containing an instance of TGVE, by default this is done via 'TEMP_DIR_ENV' env variable. If neither is given then the function copies a clean copy of the bundled TGVE version into a temporary directory.
tgve_server( path = Sys.getenv("TEMP_path_ENV"), port = 8000, host = "127.0.0.1", background = FALSE, run = TRUE )
tgve_server( path = Sys.getenv("TEMP_path_ENV"), port = 8000, host = "127.0.0.1", background = FALSE, run = TRUE )
path |
location of TGVE path to be served by plumber. |
port |
to serve from. |
host |
host to pass to plumber default 'http://127.0.0.1' to 'FALSE'. |
background |
run the R process in the background using 'callr', defaults to 'TRUE'. |
run |
whether to start the server, defaults to 'TRUE'. If not, then the created server will be returned. |
the valude returned depends on: (1) 'run', if it is FALSE then an instance of 'plumber::pr', (2) if 'run' is true and 'background' is TRUE the 'plumber::pr' instance is started and its process is returned, and (3) if 'run' is TRUE and 'background' is FALSE then a message is displayed showing the blocking ‘plumber::pr' instance’s 'path', 'port' and 'host'.
{ # This will run in the background using `callr` ps = tgve_server(background = TRUE) Sys.sleep(2) ps$kill() }
{ # This will run in the background using `callr` ps = tgve_server(background = TRUE) Sys.sleep(2) ps$kill() }
Version of the tgvejs npm package bundled in 'tgver'
Package version included as data
A character vector
This was generated using the script in the 'data' directory ('tgver.R' file).
L Hama [email protected]
{ tgver::version }
{ tgver::version }