Learn R Programming

⚠️There's a newer version (2.0.4) of this package.Take me there.

httpgd

A graphics device for R that is accessible via network protocols. This package was created to make it easier to embed live R graphics in integrated development environments and other applications. The included HTML/JavaScript client (plot viewer) aims to provide a better overall user experience when dealing with R graphics. The device asynchronously serves SVG graphics via HTTP and WebSockets.

Features

  • Fast SVG plots
  • Plot resizing and history
  • Interactive plot viewer (client)
  • Platform independent
  • Multiple concurrent clients
  • For developers:
    • HTML/JavaScript client (TypeScript module)
    • Stateless asynchronous HTTP/WebSocket API

Demo

Installation

Install httpgd from CRAN:

install.packages("httpgd")

Or get the latest development version from GitHub:

devtools::install_github("nx10/httpgd")

See system requirements for troubleshooting.

Usage

Initialize graphics device and start server with:

hgd()

Copy the displayed link in the browser or call

hgd_browse()

to open a browser window automatically.

Plot anything.

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

Every plotting library will work.

library(ggplot2)
ggplot(mpg, aes(displ, hwy, colour = class)) +
  geom_point()

Stop the server with:

dev.off()

Keyboard shortcuts

KeysResult
Navigate plot history.
+ / -Zoom in and out.
0Reset zoom level.
NJump to the newest plot.
del / DDelete plot.
alt+DClear all plots.
SDownload plot as SVG.
PDownload plot as PNG.
CCopy plot to clipboard (as PNG).
HToggle plot history (sidebar).

API & Documentation

The API documentation can be found here, and is also available as a package vignette.

Technical documentation for developers wanting to contribute to httpgd can be found here.

Benchmark

There are currently no other network graphics devices for comparison, httpgd can be used in offline mode (with hgd(webserver = FALSE)) to compare it with conventional SVG graphics devices.

This benchmark compares httpgd 1.1.0 with svglite 2.0.0.

See benchmark code

System requirements

Depends on R version ≥ 4.0 on windows, and R ≥ 3.2 on linux and macOS (a C++ compiler with basic C++17 support is required).

Note that there is a rare bug in R versions < 4.1, that leads to some plots disappearing when ggplot2 plots are resized and deleted in a specific way.

libpng and X11 are required on unix like systems (e.g. Linux, macOS).

macOS

If libpng is missing install it via:

brew install libpng

If X11 is missing the error message will include the text:

unable to load shared object [...] systemfonts/libs/systemfonts.so [...]

Install XQuartz. (see: https://github.com/r-lib/systemfonts/issues/17)

Help welcome!

The various components of httpgd are written in C++, R and TypeScript. We welcome contributions of any kind.

Other areas in need of improvement are: Testing, documentation, net security and continuous integration.

If you feel lost, the documentation might help.

Links & Articles

About & License

Depends on cpp11, later and systemfonts.

Webserver based on Boost/Beast included in the BH package.

Much of the font handling and SVG rendering code is modified code from the excellent svglite package.

This project is licensed GPL v2.0.

It includes parts of svglite (GPL ≥ 2), Belle (MIT) and fmt (MIT). The HTML client includes Material Design icons by Google which are licensed under the Apache License Version 2.0.

Full copies of the license agreements used by these components are included in ./inst/licenses.

Copy Link

Version

Install

install.packages('httpgd')

Monthly Downloads

254

Version

1.1.1

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Florian Rupprecht

Last Published

April 2nd, 2021

Functions in httpgd (1.1.1)

httpgd-package

httpgd: HTTP server graphics device
hgd_generate_token

Generate random alphanumeric token.
hgd_id

Query httpgd plot IDs
hgd_state

httpgd device status.
hgd

Asynchronous HTTP server graphics device.
hgd_inline

Inline SVG rendering.
hgd_browse

Open httpgd URL in the browser.
hgd_remove

Remove a httpgd plot page.
hgd_close

Close httpgd device.
hgd_clear

Clear all httpgd plot pages.
hgd_svg

Render httpgd plot to SVG.
hgd_url

httpgd URL.