@@ -87,7 +87,7 @@ orca <- function(p, file = "plot.png", format = tools::file_ext(file),
87
87
# ' \strong{Usage}
88
88
# '
89
89
# ' \code{
90
- # ' orca_serve$new (
90
+ # ' orca_serve(
91
91
# ' port = 5151, mathjax = FALSE, safe = FALSE, request_limit = NULL, keep_alive = TRUE,
92
92
# ' window_max_number = NULL, quiet = FALSE, debug = FALSE, ...
93
93
# ' )
@@ -143,7 +143,7 @@ orca <- function(p, file = "plot.png", format = tools::file_ext(file),
143
143
# '
144
144
# ' \dontrun{
145
145
# ' # launch the server
146
- # ' server <- orca_serve$new ()
146
+ # ' server <- orca_serve()
147
147
# '
148
148
# ' # export as many graphs as you'd like
149
149
# ' server$export(qplot(1:10), "test1.pdf")
@@ -161,56 +161,54 @@ orca <- function(p, file = "plot.png", format = tools::file_ext(file),
161
161
# ' unlink("test2.pdf")
162
162
# ' }
163
163
164
- orca_serve <- R6 :: R6Class(
165
- " orcaServe" ,
166
- public = list (
167
- process = NULL ,
168
- port = NULL ,
169
- initialize = function (port = 5151 , mathjax = FALSE , safe = FALSE , request_limit = NULL ,
170
- keep_alive = TRUE , window_max_number = NULL , quiet = FALSE ,
171
- debug = FALSE , xvfb = FALSE , ... ) {
172
-
173
- # make sure we have the required infrastructure
174
- orca_available()
175
- try_library(" processx" , " orca_serve" )
176
-
177
- # use main bundle since any plot can be thrown at the server
178
- plotlyjs <- plotlyMainBundle()
179
- plotlyjs_file <- file.path(plotlyjs $ src $ file , plotlyjs $ script )
180
-
181
- args <- c(
182
- " serve" ,
183
- " -p" , port ,
184
- " --plotly" , plotlyjs_file ,
185
- if (safe ) " --safe-mode" ,
186
- # if (orca_version() >= "1.1.1") "--graph-only",
187
- if (keep_alive ) " --keep-alive" ,
188
- if (debug ) " --debug" ,
189
- if (quiet ) " --quiet"
190
- )
191
-
192
- if (! is.null(request_limit ))
193
- args <- c(args , " --request-limit" , request_limit )
194
-
195
- if (! is.null(window_max_number ))
196
- args <- c(args , " --window-max-number" , window_max_number )
197
-
198
- if (! is.null(tryNULL(mapbox_token())))
199
- args <- c(args , " --mapbox-access-token" , mapbox_token())
200
-
201
- if (isTRUE(mathjax ))
202
- args <- c(args , " --mathjax" , file.path(mathjax_path(), " MathJax.js" ))
203
-
204
- if (xvfb ) {
205
- self $ process <- processx :: process $ new(" xvfb-run" , c(" orca" , args ), ... )
206
- } else {
207
- self $ process <- processx :: process $ new(" orca" , args , ... )
208
- }
209
-
210
- self $ port <- port
164
+
165
+ orca_serve <- function (port = 5151 , mathjax = FALSE , safe = FALSE , request_limit = NULL ,
166
+ keep_alive = TRUE , window_max_number = NULL , quiet = FALSE ,
167
+ debug = FALSE , xvfb = FALSE , ... ) {
168
+
169
+ # make sure we have the required infrastructure
170
+ orca_available()
171
+ try_library(" processx" , " orca_serve" )
172
+
173
+ # use main bundle since any plot can be thrown at the server
174
+ plotlyjs <- plotlyMainBundle()
175
+ plotlyjs_file <- file.path(plotlyjs $ src $ file , plotlyjs $ script )
176
+
177
+ args <- c(
178
+ " serve" ,
179
+ " -p" , port ,
180
+ " --plotly" , plotlyjs_file ,
181
+ if (safe ) " --safe-mode" ,
182
+ # if (orca_version() >= "1.1.1") "--graph-only",
183
+ if (keep_alive ) " --keep-alive" ,
184
+ if (debug ) " --debug" ,
185
+ if (quiet ) " --quiet"
186
+ )
187
+
188
+ if (! is.null(request_limit ))
189
+ args <- c(args , " --request-limit" , request_limit )
190
+
191
+ if (! is.null(window_max_number ))
192
+ args <- c(args , " --window-max-number" , window_max_number )
193
+
194
+ if (! is.null(tryNULL(mapbox_token())))
195
+ args <- c(args , " --mapbox-access-token" , mapbox_token())
196
+
197
+ if (isTRUE(mathjax ))
198
+ args <- c(args , " --mathjax" , file.path(mathjax_path(), " MathJax.js" ))
199
+
200
+ process <- if (xvfb ) {
201
+ processx :: process $ new(" xvfb-run" , c(" orca" , args ), ... )
202
+ } else {
203
+ processx :: process $ new(" orca" , args , ... )
204
+ }
205
+
206
+ list (
207
+ port = port ,
208
+ close = function () {
209
+ process $ kill()
211
210
},
212
211
export = function (p , file = " plot.png" , format = tools :: file_ext(file ), scale = NULL , width = NULL , height = NULL ) {
213
-
214
212
# request/response model works similarly to plotly_IMAGE()
215
213
bod <- list (
216
214
figure = plotly_build(p )$ x [c(" data" , " layout" )],
@@ -220,19 +218,17 @@ orca_serve <- R6::R6Class(
220
218
scale = scale
221
219
)
222
220
res <- httr :: POST(
223
- paste0(" http://127.0.0.1:" , self $ port ),
221
+ paste0(" http://127.0.0.1:" , port ),
224
222
body = to_JSON(bod )
225
223
)
226
224
httr :: stop_for_status(res )
227
225
httr :: warn_for_status(res )
228
226
con <- httr :: content(res , as = " raw" )
229
227
writeBin(con , file )
230
- },
231
- close = function () {
232
- self $ process $ kill()
233
228
}
234
229
)
235
- )
230
+ }
231
+
236
232
237
233
orca_available <- function () {
238
234
if (Sys.which(" orca" ) == " " ) {
0 commit comments