File: save_image.Rd

package info (click to toggle)
r-cran-plotly 4.10.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 30,636 kB
  • sloc: javascript: 195,272; sh: 24; makefile: 6
file content (78 lines) | stat: -rw-r--r-- 2,976 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/kaleido.R
\name{save_image}
\alias{save_image}
\alias{kaleido}
\title{Save plot as a static image}
\usage{
save_image(p, file, ..., width = NULL, height = NULL, scale = NULL)

kaleido(...)
}
\arguments{
\item{p}{a plot object.}

\item{file}{a file path with a suitable file extension (png, jpg, jpeg,
webp, svg, or pdf).}

\item{...}{not currently used.}

\item{width, height}{The width/height of the exported image in layout
pixels. If \code{scale} is 1, this will also be the width/height of the exported
image in physical pixels.}

\item{scale}{The scale factor to use when exporting
the figure. A scale factor larger than 1.0 will increase the image
resolution with respect to the figure's layout pixel dimensions. Whereas as
scale factor of less than 1.0 will decrease the image resolution.}
}
\value{
For \code{save_image()}, the generated \code{file}. For \code{kaleido()}, an environment that contains:
\itemize{
\item \code{transform()}: a function to convert plots objects into static images. This function has the same signature (i.e., arguments) as \code{save_image()}
\item \code{shutdown()}: a function for shutting down any currently running subprocesses
that were launched via \code{transform()}
\item \code{scope}: a reference to the underlying \code{kaleido.scopes.plotly.PlotlyScope}
python object. Modify this object to customize the underlying Chromium
subprocess and/or configure other details such as URL to plotly.js, MathJax, etc.
}
}
\description{
Static image exporting via \href{https://github.com/plotly/Kaleido/}{the kaleido python package}. \code{kaleido()} imports
kaleido into a \pkg{reticulate}d Python session and returns a \verb{$transform()}
method for converting R plots into static images. \code{save_image()} provides a convenience wrapper around \code{kaleido()$transform()}.
}
\section{Installation}{


\code{kaleido()} requires \href{https://github.com/plotly/Kaleido/}{the kaleido python package} to be usable via the \pkg{reticulate} package. Here is a recommended way to do the installation:

\if{html}{\out{<div class="sourceCode">}}\preformatted{install.packages('reticulate')
reticulate::install_miniconda()
reticulate::conda_install('r-reticulate', 'python-kaleido')
reticulate::conda_install('r-reticulate', 'plotly', channel = 'plotly')
reticulate::use_miniconda('r-reticulate')
}\if{html}{\out{</div>}}
}

\examples{
\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}

\dontrun{
  # Save a single image
  p <- plot_ly(x = 1:10)
  tmp <- tempfile(fileext = ".png")
  save_image(p, tmp)
  file.show(tmp)

  # Efficiently save multiple images
  scope <- kaleido()
  for (i in 1:5) {
    scope$transform(p, tmp)
  }
  # Remove and garbage collect to remove 
  # R/Python objects and shutdown subprocesses
  rm(scope); gc()
}
\dontshow{\}) # examplesIf}
}