Skip to content

Instantly share code, notes, and snippets.

@HenrikBengtsson
Last active September 24, 2016 22:03
Show Gist options
  • Save HenrikBengtsson/b248b0274368db77d41367ecf7724111 to your computer and use it in GitHub Desktop.
Save HenrikBengtsson/b248b0274368db77d41367ecf7724111 to your computer and use it in GitHub Desktop.
Checking local rendering of remotely generated objects

Remote evaluation local display

Visualization

Works:

  • Base R Graphics
  • ggplot2
  • plotly
  • highcharter
  • rbokeh
  • ggvis
  • googleVis
  • recharts (not on CRAN)

Requires tweaks:

  • rCharts (on GitHub only)

Base R Graphics

library("future")
plan(remote, workers = remote_machine)

library("R.devices")
p %<-% capturePlot({
  plot(iris)
})

print(p)

ggvis

library("future")
plan(remote, workers = remote_machine)

library("ggvis")

p %<-% {
  mtcars %>%
    ggvis(~mpg, ~wt) %>%
    layer_points() %>%
    layer_smooths()
}

print(p)

To install on remote machine, do:

todos %<-% install.packages("ggvis")

googleVis

library("future")
plan(remote, workers = remote_machine)

library("googleVis")
df <- data.frame(country=c("US", "GB", "BR"), 
                 val1=c(10,13,14), 
                 val2=c(23,12,32))

Line %<-% gvisLineChart(df)
plot(Line)

To install on remote machine, do:

todos %<-% install.packages("googleVis")

highcharter

library("future")
plan(remote, workers = remote_machine)

library("highcharter")
p %<-% {
  highchart() %>% 
    hc_chart(type = "column") %>% 
    hc_title(text = "A highcharter chart") %>% 
    hc_xAxis(categories = 2012:2016) %>% 
    hc_add_series(data = c(3900,  4200,  5700,  8500, 11900),
                  name = "Downloads")
}
print(p)

To install on remote machine, do:

todos %<-% install.packages("highcharter")

rbokeh

library("future")
plan(remote, workers = remote_machine)

library("rbokeh")
p %<-% {
  figure() %>% ly_points(Sepal.Length, Sepal.Width, data = iris, color = Species, glyph = Species,hover = list(Sepal.Length, Sepal.Width))
}
print(p)

To install on remote machine, do:

todos %<-% install.packages("rbokeh")

plotly

library("future")
plan(remote, workers = remote_machine)

library("plotly")
p %<-% {
  plot_ly(economics, x = ~date, line = list(color = "black")) %>%
     add_trace(y = ~uempmed, mode = "markers+lines") %>%
     add_lines(y = ~psavert) %>%
     layout(title = "Setting global trace attributes")
}
print(p)

To install on remote machine, do:

todos %<-% install.packages("plotly")  ## CRAN version
todos %<-% source("http://callr.org/install#ropensci/plotly")

recharts

library("future")
plan(remote, workers = remote_machine)

library("recharts")
p <- ePoints(iris, ~Sepal.Length, ~Sepal.Width, series = ~Species)
print(p)
todos %<-% install.packages("recharts", repos = c("http://yihui.name/xran", "http://cloud.r-project.org"))

rCharts (needs tweaks)

library("future")
plan(remote, workers = remote_machine)

library("rCharts")
hair_eye <- as.data.frame(HairEyeColor)
p %<-% rPlot(Freq ~ Hair | Eye, color = 'Eye', data = hair_eye, type = 'bar')

print(p)
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file '/home/hb/R/i686-pc-linux-gnu-library/3.3/rCharts/libraries/polycharts/config.yml': No such file or directory

The problem is that the Polycharts object p created remotely has elements with absolute pathnames hardwired to the remote machine. If tweaked, the graphics is displayed in the local browser, e.g.

pathR %<-% system.file(package="rCharts")
print(pathR)
## [1] "/home/hb/R/i686-pc-linux-gnu-library/3.3/rCharts"
pathL <- system.file(package="rCharts")
print(pathL)
## [1] "/home/hb/R/x86_64-pc-linux-gnu-library/3.3/rCharts"
p$LIB$url <- gsub(pathR, pathL, p$LIB$url, fixed=TRUE)
p$templates$script <- gsub(pathR, pathL, p$templates$script, fixed=TRUE)

print(p)

Is this a problem with rChart or shiny?

To install on remote machine, do:

todos %<-% source("http://callr.org/install#ramnathv/rCharts")

Programming Tools

covr

library("future")
plan(remote, workers = remote_machine)

library("covr")
c %<-% package_coverage(quiet=FALSE)
print(c)
## globals Coverage: 100.00%
## R/cleanup.R: 100.00%
## R/findGlobals.R: 100.00%
## R/Globals-class.R: 100.00%
## R/globalsOf.R: 100.00%
## R/packagesOf.R: 100.00%
## R/utils.R: 100.00%
## R/walkAST.R: 100.00%

report(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment