% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plotly_Utils.R
\name{export_plotly}
\alias{export_plotly}
\title{Export plotly plot}
\usage{
export_plotly(
  p,
  file,
  width = NULL,
  height = NULL,
  scale = NULL,
  units = "px",
  show = TRUE
)
}
\arguments{
\item{p}{The plot to which the shape should be added. Default is the
\code{plotly::last_plot()}.}

\item{file}{A file path with a suitable file extension (png, jpg, jpeg, webp, svg, or pdf).
Unlike \code{save_image}, the \code{file} argument may include the full path and filename
other than in the current working directory.}

\item{width, height}{The width/height of the exported image in pixels,
mutliplied by \code{scale}.}

\item{scale}{The scale factor to use when exporting the figure. Default is 1.0.
A scale factor larger than 1.0 will increase the image size,
and less than 1.0 will decrease the image size. Note that the documentation
for \code{save_image} says that this argument changes the resolution, but that is
not true. The resolution will remain at 72 pixels/inch (28.3 px/cm), which is
the default for R. To increase the resolution, export to .pdf or .svg and use
an external program, such as Adobe Acrobat, Acrobat Reader, or Mac Preview.}

\item{units}{Units for \code{width} and \code{height}. Default is pixels ("px").
Alternatives are inches ("in") or centimeters ("cm")}

\item{show}{Show the exported image in R via \code{\link[base:file.show]{base::file.show()}}. If export
format is pdf, it will open the system default pdf viewer. Default is \code{TRUE}.}
}
\value{
Plot \code{p} will be exported to \code{file} with format determined by the
extension for \code{file}.
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}}

Wrapper around \code{\link[plotly:save_image]{plotly::save_image()}}.
}
\details{
This function improves the experience with the native plotly method of exporting
plots to static images. Much of the online documentation points towards using
the orca package, but the R help indicates that this method has been superseded
by the kaleido python package, made accesible in R via the reticulate package and
installation of the miniconda package manager.

These steps are all outlined in the help for \code{\link[plotly:save_image]{plotly::save_image()}}, but one step
is neglected. It is necessary to execute the following line of code at the end:
\code{reticulate::py_run_string("import sys")}.

This function will check to see that all installations are in place and offer to
install if not.

Many of the arguments are the same as for \code{save_image} and are passed directly
to that function.
}
\examples{
\dontrun{
NPex$op$plot(stats = list(x = 0.9)) |>
  export_plotly(file = "op.png", width = 12, height = 6, units = "in")
}
}
\seealso{
\code{\link[plotly:save_image]{plotly::save_image()}}
}
\author{
Michael Neely
}
