Learn R Programming

httpgd (version 1.0.1)

hgd: Asynchronous HTTP server graphics device.

Description

This function initializes a httpgd graphics device and starts a local webserver, that allows for access via HTTP and WebSockets. A link will be printed by which the web client can be accessed using a browser.

Usage

hgd(
  host = "127.0.0.1",
  port = 0,
  width = 720,
  height = 576,
  bg = "white",
  pointsize = 12,
  system_fonts = list(),
  user_fonts = list(),
  cors = FALSE,
  token = TRUE,
  silent = FALSE,
  websockets = TRUE,
  webserver = TRUE,
  fix_text_width = TRUE
)

Arguments

host

Server hostname. Set to "0.0.0.0" to enable remote access. We recommend to only enable remote access in trusted networks. The network security of httpgd has not yet been properly tested.

port

Server port. If this is set to 0, an open port will be assigned.

width

Graphics device width (pixels).

height

Graphics device height (pixels).

bg

Background color.

pointsize

Graphics device point size.

system_fonts

Named list of font names to be aliased with fonts installed on your system. If unspecified, the R default families sans, serif, mono and symbol are aliased to the family returned by systemfonts::font_info().

user_fonts

Named list of fonts to be aliased with font files provided by the user rather than fonts properly installed on the system. The aliases can be fonts from the fontquiver package, strings containing a path to a font file, or a list containing name and file elements with name indicating the font alias in the SVG output and file the path to a font file.

cors

Toggles Cross-Origin Resource Sharing (CORS) header. When set to TRUE, CORS header will be set to "*".

token

(Optional) security token. When set, all requests need to include a token to be allowed. (Either in a request header (X-HTTPGD-TOKEN) field or as a query parameter.) This parameter can be set to TRUE to generate a random 8 character alphanumeric token. A random token of the specified length is generated when it is set to a number. FALSE deactivates the token.

silent

When set to FALSE no information will be printed to console.

websockets

Use websockets.

webserver

Can be set to FALSE for offline mode. In offline mode the device is only accessible via R.

fix_text_width

Should the width of strings be fixed so that it doesn't change between SVG renderers depending on their font rendering? Defaults to TRUE. If TRUE each string will have the textLength CSS property set to the width calculated by systemfonts and lengthAdjust='spacingAndGlyphs'. Setting this to FALSE can be beneficial for heavy post-processing that may change content or style of strings, but may lead to inconsistencies between strings and graphic elements that depend on the dimensions of the string (e.g. label borders and background).

Value

No return value, called to initialize graphics device.

Details

All font settings and descriptions are adopted from the excellent 'svglite' package.

Examples

Run this code
# NOT RUN {
hgd() # Initialize graphics device and start server
hgd_browse() # Or copy the displayed link in the browser

# Plot something
x = seq(0, 3 * pi, by = 0.1)
plot(x, sin(x), type = "l")

dev.off() # alternatively: hgd_close()
# }

Run the code above in your browser using DataLab