ManuelHentschel / httpgd

Asynchronous http server graphics device for R.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

httpgd

R-CMD-check CRAN downloads

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

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

Keys Result
Navigate plot history.
+ / - Zoom in and out.
0 Reset zoom level.
N Jump to the newest plot.
del / D Delete plot.
alt+D Clear all plots.
S Download plot as SVG.
P Download plot as PNG.
C Copy plot to clipboard (as PNG).
H Toggle 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: r-lib/systemfonts#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.

About

Asynchronous http server graphics device for R.

License:Other


Languages

Language:C++ 84.1%Language:R 7.0%Language:TypeScript 3.2%Language:JavaScript 3.0%Language:HTML 2.0%Language:CSS 0.7%Language:C 0.0%