Movatterモバイル変換


[0]ホーム

URL:


Type:Package
Title:Interface to 'D3' Visualizations
Version:0.2.6
Description:Suite of tools for using 'D3', a library for producing dynamic, interactive data visualizations. Supports translating objects into 'D3' friendly data structures, rendering 'D3' scripts, publishing 'D3' visualizations, incorporating 'D3' in R Markdown, creating interactive 'D3' applications with Shiny, and distributing 'D3' based 'htmlwidgets' in R packages.
License:BSD_3_clause + file LICENSE
Encoding:UTF-8
Depends:R (≥ 3.1.2)
Imports:htmlwidgets (≥ 1.2), htmltools, jsonlite, rstudioapi
Suggests:knitr, rmarkdown, R6, shiny, shinytest, testthat, webshot
RoxygenNote:7.1.2
URL:https://rstudio.github.io/r2d3/,https://github.com/rstudio/r2d3
BugReports:https://github.com/rstudio/r2d3/issues
VignetteBuilder:knitr
NeedsCompilation:no
Packaged:2022-02-28 16:22:53 UTC; nicholasstrayer
Author:Nick Strayer [aut, cre], Javier Luraschi [aut], JJ Allaire [aut], Mike Bostock [ctb, cph] (d3.js library, https://d3js.org), RStudio [cph]
Maintainer:Nick Strayer <nick.strayer@rstudio.com>
Repository:CRAN
Date/Publication:2022-02-28 16:50:02 UTC

Convert object to D3 data

Description

Generic method to transform R objects into D3 friendly data.

Usage

as_d3_data(x, ...)## Default S3 method:as_d3_data(x, ...)

Arguments

x

data

...

Additional arguments for generic methods

Details

The value returned fromas_d3_data() should be one of:


Shiny bindings for d3

Description

Output and render functions for using d3 within Shinyapplications and interactive Rmd documents.

Usage

d3Output(outputId, width = "100%", height = "400px")renderD3(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width,height

Must be a valid CSS unit (like'100%','400px','auto') or a number, which will be coerced to astring and have'px' appended.

expr

An expression that generates a d3

env

The environment in which to evaluateexpr.

quoted

Isexpr a quoted expression (withquote())? Thisis useful if you want to save an expression in a variable.


Default sizing policy for r2d3 widgets

Description

Default sizing policy for r2d3 widgets

Usage

default_sizing()

Details

Usehtmlwidgets::sizingPolicy() to specify analternate policy.


D3 HTML dependencies

Description

Create HTML dependencies for D3 and optional extensions

Usage

html_dependencies_d3(version = c("6", "5", "4", "3"), extensions = NULL)

Arguments

version

Major version of D3

extensions

D3 extensions to include. Currently the only supportedextension is "jetpack" (https://github.com/gka/d3-jetpack).

Details

Create list of HTML dependencies for D3. Each version hasa distinct root D3 object so it's possible to combine multiple versionsof D3 on a single page. For example, D3 v5 is accessed viad3v5 andD3 v4 is accessed viad3v4. Note however that D3 v3 is accessed viasimplyd3 (for compabibilty with existing htmlwidgets that usethis form).

Note

This function is exported for use by htmlwidgets. If you areusing ther2d3() function to include D3 code within a documentor application this dependency is included automatically so callingthis function is unnecessary.

Examples

library(r2d3)r2d3(  data = c (0.3, 0.6, 0.8, 0.95, 0.40, 0.20),  script = system.file("examples/barchart.js", package = "r2d3"),  dependencies = "d3-jetpack")

D3 visualization

Description

Visualize data using a custom D3 visualization script

Usage

r2d3(  data,  script,  css = "auto",  dependencies = NULL,  options = NULL,  d3_version = c("6", "5", "4", "3"),  container = "svg",  elementId = NULL,  width = NULL,  height = NULL,  sizing = default_sizing(),  viewer = c("internal", "external", "browser"))

Arguments

data

Data to be passed to D3 script.

script

JavaScript file containing the D3 script.

css

CSS file containing styles. The default value "auto" will use any CSS filelocated alongside the script file with the same stem (e.g. "barplot.css" would beused for "barplot.js") as well as any CSS file with the name "styles.css".

dependencies

Additional HTML dependencies. These can take the form of paths toJavaScript or CSS files, or alternatively can be fully specified dependencies createdwithhtmltools::htmlDependency.

options

Options to be passed to D3 script.

d3_version

Major D3 version to use, the latest minor version is automaticallypicked.

container

The 'HTML' container of the D3 output.

elementId

Use an explicit element ID for the widget (rather than anautomatically generated one). Useful if you have other JavaScript that needs toexplicitly discover and interact with a specific widget instance.

width

Desired width for output widget.

height

Desired height for output widget.

sizing

Widget sizing policy (seehtmlwidgets::sizingPolicy).

viewer

"internal" to use the RStudio internal viewer pane for output; "external"to display in an external RStudio window; "browser" to display in an externalbrowser.

Details

In order to scope CSS styles when multiple widgets are rendered, the Shadow DOM andthe wecomponents polyfill is used, this feature can be turned off by setting ther2d3.shadow option toFALSE.

Examples

library(r2d3)r2d3(  data = c (0.3, 0.6, 0.8, 0.95, 0.40, 0.20),  script = system.file("examples/barchart.js", package = "r2d3"))

Objects exported from other packages

Description

These objects are imported from other packages. Follow the linksbelow to see their documentation.

htmlwidgets

sizingPolicy

jsonlite

read_json


Save a D3 visualization as HTML

Description

Save a D3 visualization to an HTML file (e.g. for sharing with others).

Usage

save_d3_html(  d3,  file,  selfcontained = TRUE,  libdir = NULL,  background = "white",  title = "D3 Visualization",  knitrOptions = list())

Arguments

d3

D3 visualization to save

file

File to save HTML into

selfcontained

Whether to save the HTML as a single self-contained file(with external resources base64 encoded) or a file with external resourcesplaced in an adjacent directory.

libdir

Directory to copy HTML dependencies into (defaults tofilename_files).

background

Text string giving the html background color of the widget.Defaults to white.

title

Text to use as the title of the generated page.

knitrOptions

A list ofknitr chunk options.

Details

Usingselfcontained set toTRUE requirespandocto be installed.

See Also

save_d3_png()

Examples

library(r2d3)viz <- r2d3(  data = c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20),  script = system.file("examples/barchart.js", package = "r2d3"))save_d3_html(  viz,  file = tempfile(fileext = ".html"),  selfcontained = FALSE)

Save a D3 visualization as a PNG image

Description

Save a D3 visualization to PNG (e.g. for including in another document).

Usage

save_d3_png(  d3,  file,  background = "white",  width = 992,  height = 744,  delay = 0.2,  zoom = 1)

Arguments

d3

D3 visualization to save

file

File to save HTML into

background

Text string giving the html background color of the widget.Defaults to white.

width

Image width

height

Image height

delay

Time to wait before taking screenshot, in seconds. Sometimes alonger delay is needed for all assets to display properly.

zoom

A number specifying the zoom factor. A zoom factor of 2 willresult in twice as many pixels vertically and horizontally. Note thatusing 2 is not exactly the same as taking a screenshot on a HiDPI (Retina)device: it is like increasing the zoom to 200 doubling the height andwidth of the browser window. This differs from using a HiDPI devicebecause some web pages load different, higher-resolution images when theyknow they will be displayed on a HiDPI device (but using zoom will notreport that there is a HiDPI device).

Details

PNG versions of D3 visualizations are created by displaying them inan offscreen web browser and taking a screenshot of the rendered web page.

Using thesave_d3_png() function requires that you install thewebshot package, as well as the phantom.js headless browser (whichyou can install using the functionwebshot::install_phantomjs()).

See Also

save_d3_html()


[8]ページ先頭

©2009-2025 Movatter.jp