Skip to contents

Server-side function to construct a URL to a site that shows a personalised growth chart. The site includes a navigation bar so that the end user can interact to chart choices.

Usage

request_site(
  txt = "",
  sitehost = "",
  session = "",
  format = "1.0",
  upload = TRUE,
  loc = "",
  ...
)

Arguments

txt

A JSON string, URL or file with the data in JSON format. The input data adhere to specification BDS JGZ 3.2.5, and are converted to JSON according to schema.

sitehost

The host that renders the site. Normally, that would be equal to the host on which JAMES runs. If not specified, the function throws a warning and sets sitehost to "http://localhost".

session

Alternative to txt. Session key where input data is uploaded on sitehost.

format

String. JSON data schema version number. There are currently three schemas supported: "1.0", "1.1", "2.0" and "3.0". Formats "1.0" and "1.1" are included for backward compatibility only. Use format = "3.0" for new applications.

upload

Logical. If TRUE then request_site() will upload the data in txt to sitehost and return a site address with the ?session= query appended. Setting (FALSE) just appends ?txt= to the site url, thus deferring validation and conversion to internal representation to the site.

loc

Alternative to txt. Location where input data is uploaded. Argument loc is deprecated and will disappear in Nov 2022; please use session instead.

...

Ignored

Value

URL composed of JAMES server, possibly appended by query string starting with ?txt= or ?session=.

Details

One of txt or session needs to be specified. If both are given, txt takes precedence. If neither is given, then the function returns the base site without any data.

Examples

fn <- system.file("testdata", "client3.json", package = "james")
js <- jsonlite::toJSON(jsonlite::fromJSON(fn), auto_unbox = TRUE)
url <- "https://groeidiagrammen.nl/ocpu/library/james/testdata/client3.json"
host <- "http://localhost"

# solutions that upload the data and create a URL with the `?session=` query parameter
if (FALSE) {
# upload file - works with docker on localhost
site <- request_site(sitehost = host, txt = fn)
# browseURL(site)

# upload JSON string
site <- request_site(sitehost = host, txt = js)
site
# browseURL(site)

# upload URL
site <- request_site(sitehost = host, txt = url)
site
# browseURL(site)

# same, but in two steps, starting from file name
# this also works for js and url
resp <- jamesclient::james_post(path = "data/upload", txt = fn)
session <- resp$session
site <- request_site(sitehost = host, session = session)
site
# browseURL(site)

# solutions that create an immediate ?txt=[..data..] query
# this method does not create a cache on the server
site <- request_site(sitehost = host, txt = js, upload = FALSE)
# browseURL(site)
}