|
8 | 8 | #' @section Installation: |
9 | 9 | #' |
10 | 10 | #' `kaleido()` requires [the kaleido python |
11 | | -#' package](https://github.com/plotly/Kaleido/) to be usable via the \pkg{reticulate} package. Here is a recommended way to do the installation: |
| 11 | +#' package](https://github.com/plotly/Kaleido/) to be usable via the |
| 12 | +#' \pkg{reticulate} package. If you're starting from scratch, you install |
| 13 | +#' eveything you need with the following R code: |
12 | 14 | #' |
13 | 15 | #' ``` |
14 | | -#' install.packages('reticulate') |
15 | | -#' reticulate::install_miniconda() |
16 | | -#' reticulate::conda_install('r-reticulate', 'python-kaleido') |
17 | | -#' reticulate::conda_install('r-reticulate', 'plotly', channel = 'plotly') |
18 | | -#' reticulate::use_miniconda('r-reticulate') |
| 16 | +#' install.packages("reticulate") |
| 17 | +#' library(reticulate) |
| 18 | +#' use_python(install_python()) |
| 19 | +#' py_install(c("kaleido", "plotly")) |
19 | 20 | #' ``` |
20 | 21 | #' |
21 | 22 | #' @param ... not currently used. |
@@ -65,16 +66,40 @@ save_image <- function(p, file, ..., width = NULL, height = NULL, scale = NULL) |
65 | 66 | #' @rdname save_image |
66 | 67 | #' @export |
67 | 68 | kaleido <- function(...) { |
68 | | - if (!rlang::is_installed("reticulate")) { |
69 | | - stop("`kaleido()` requires the reticulate package.") |
70 | | - } |
71 | | - if (!reticulate::py_available(initialize = TRUE)) { |
72 | | - stop("`kaleido()` requires `reticulate::py_available()` to be `TRUE`. Do you need to install python?") |
| 69 | + rlang::check_installed("reticulate") |
| 70 | + |
| 71 | + call_env <- rlang::caller_env() |
| 72 | + |
| 73 | + if (!reticulate::py_available()) { |
| 74 | + rlang::abort(c("`{reticulate}` wasn't able to find a Python environment.", |
| 75 | + i = "If you have an existing Python installation, use `reticulate::use_python()` to inform `{reticulate}` of it.", |
| 76 | + i = "To have `{reticulate}` install Python for you, `reticulate::install_python()`." |
| 77 | + ), call = call_env) |
73 | 78 | } |
74 | 79 |
|
| 80 | + tryCatch( |
| 81 | + reticulate::import("plotly"), |
| 82 | + error = function(e) { |
| 83 | + rlang::abort(c( |
| 84 | + "The `plotly` Python package is required for static image exporting.", |
| 85 | + i = "Please install it via `reticulate::py_install('plotly')`." |
| 86 | + ), call = call_env) |
| 87 | + } |
| 88 | + ) |
| 89 | + |
| 90 | + kaleido <- tryCatch( |
| 91 | + reticulate::import("kaleido"), |
| 92 | + error = function(e) { |
| 93 | + rlang::abort(c( |
| 94 | + "The `kaleido` Python package is required for static image exporting.", |
| 95 | + i = "Please install it via `reticulate::py_install('kaleido')`." |
| 96 | + ), call = call_env) |
| 97 | + } |
| 98 | + ) |
| 99 | + |
75 | 100 | py <- reticulate::py |
76 | 101 | scope_name <- paste0("scope_", new_id()) |
77 | | - py[[scope_name]] <- reticulate::import("kaleido")$scopes$plotly$PlotlyScope( |
| 102 | + py[[scope_name]] <- kaleido$scopes$plotly$PlotlyScope( |
78 | 103 | plotlyjs = plotlyMainBundlePath() |
79 | 104 | ) |
80 | 105 |
|
|
0 commit comments