Code Monkey home page Code Monkey logo

httpgd's Introduction

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 graphics via HTTP and WebSockets.

Features

  • Fast plotting
  • Plot resizing and history
  • Interactive plot viewer (client)
  • Platform independent
  • Export to various image formats (SVG, PNG, PDF, EPS, ...)
  • Multiple concurrent clients
  • For developers:
    • Stateless asynchronous HTTP/WebSocket API
    • In-memory access to rendered plots
    • HTML/JavaScript client (TypeScript module)

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). Cairo is required on unix like systems to enable PNG, PDF, EPS and PS renderers.

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.

httpgd's People

Contributors

nx10 avatar renkun-ken avatar jeroen avatar kguidonimartins avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.