1

I can get correct R plots with text labels (ggplot and ggrepel) from a remote R plot function through opencpu API, but get wrong plots through ocpu.rplot call, using opencpu-0.4.js, with the same remote R plot function. The wrong plot got no text labels on them.

I write a small reproducible example for this problem: HTML code: https://github.com/cywhale/ODB/blob/master/opencpu_test/ocpu_test.html

in this html js, use opcu.call rplot to call plot_test API to plot, and session.getLoc() to get R graphics in R/.val/png, put both two graphics in the same html

Run this html and get the reproducible results on my server: https://bio.odb.ntu.edu.tw/test/ocpu_test.html

A remote R plot function : plot_test()

#' generate a test graph by ggplot+ggrepel, use offical ex: https://cran.r-project.org/web/packages/ggrepel/vignettes/ggrepel.html
#' @return A ggplot graph
#' @examples plot_test()
#' @rdname plot_test
#' @export
plot_test <- function() {
  set.seed(42)
  data("mtcars")
  dat2 <- subset(mtcars, wt > 3 & wt < 4)
  # Hide all of the text labels.
  dat2$car <- ""
  # Let's just label these items.
  ix_label <- c(2,3,16)
  dat2$car[ix_label] <- rownames(dat2)[ix_label]

  g1 <- ggplot(dat2, aes(wt, mpg, label = car)) +
    geom_point(color = ifelse(dat2$car == "", "grey50", "red")) +
    geom_text_repel()

  print(g1)
}

ocpu.rplot on upper part and correct results on lower part

The two graphics are different. The texts and labels that use ggrepel package disappear in ocpu.call rplot. But in R/.val/png, the graphics is correct. Expect that ocpu.call rplot should return the correct plot with labels as the results in R/.val/png. Appreciate any comments that may help to clarify or solve this problem. Thanks.

  • Does non-ggrepel geom_text behave as expected? If so, it might be that the `ocpu.call rplot` doesn't evaluate the grid `makeContent` function properly. If you would test the ggforce `geom_shape()` and derivatives with a radius for rounded corners set, do these evaluate properly? (These also rely on `makeContent` evaluation) – teunbrand Sep 19 '19 at 09:30
  • @teunbrand Yes, you're right. I tried these at https://bio.odb.ntu.edu.tw/test/ocpu_test.html geom_text can keep, while ggforce::geom_shape() lost. – cywhale Weng Sep 19 '19 at 14:29
  • Well, it's a step in dissecting the problem, but I wouldn't know how to fix it as I know nothing about the opencpu api. Maybe explicitly loading the grid package as to expose the `makeContent` generic to the namespace might help. – teunbrand Sep 19 '19 at 18:53
  • I can use Imports: grid, (or ggrepel, ggforce) or @importFrom grid makeContent so that it's exposed to my R package's (with plot_test() function) namespace. It seems not work, but I'm not very sure what I did is coincide with what you suggest. – cywhale Weng Sep 20 '19 at 07:06

0 Answers0