HTML Widgets for graphical comparison

Share:

Description

These widgets can be used at the console and embedded in a R Markdown document or Shiny application.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
widget_toggle_(before, after, width = NULL, height = NULL)

widget_slide_(before, after, width = NULL, height = NULL)

widget_diff_(before, after, width = NULL, height = NULL)

widget_toggle(before, after, width = NULL, height = NULL)

widget_slide(before, after, width = NULL, height = NULL)

widget_diff(before, after, width = NULL, height = NULL)

Arguments

before

The picture that is taken as reference.

after

The picture against which the reference is compared.

width

Fixed width for widget (in css units). The default is NULL, which results in intelligent automatic sizing based on the widget's container.

height

Fixed height for widget (in css units). The default is NULL, which results in intelligent automatic sizing based on the widget's container.

Details

The regular versions take plots or functions as before and after arguments (see expect_doppelganger() for details). The versions suffixed with underscores take HTML image sources. These can be paths to SVG files or inlined SVG images. Currently, widget_diff_() is compatible only with inlined images.

Examples

1
2
3
4
5
6
7
8
p1 <- function() hist(mtcars$disp)
p2 <- function() hist(mtcars$drat)

# You can also call these functions in a R Markdown document or
# in a Shiny application:
widget_toggle(p1, p2)
widget_slide(p1, p2)
widget_diff(p1, p2)