Reputation: 2663
I am on a windows 10 machine. Trying to experiment with htmlwidget development.
To test things out, I have a local clone of the sigma package, which is the example provided in the htmlwidgets
tutorials.
Based on this post, I am lead to believe that devtools would work fine with htmlwidgets. However if I do
library(devtools)
load_all()
sigma(system.file("examples/ediaspora.gexf.xml", package = "sigma"))
The resulting widget is blank. If I examine the html code of the output, I see that the required javascript files for sigma is not loaded.
However if I do
library(devtools)
install()
library(sigma)
sigma(system.file("examples/ediaspora.gexf.xml", package = "sigma"))
I get the network. Examining the html of the output reveals that the required javascript files are loaded this time.
Am I supposed to be installing the package I am developing to be able to test it out? Is there a way to work around this behaviour?
Upvotes: 1
Views: 158
Reputation: 4124
From reading the solution in that post, devtools works with htmlwidgets if you use one of two workarounds (just summarizing them here):
Use devtools::load_all()
on the htmlwidgets package, and then load_all()
your widget package. This would require you to have the htmlwidgets source somewhere locally. For example, clone the https://github.com/ramnathv/htmlwidgets repo to ~/htmlwidgets
, and then run devtools::load_all("~/htmlwidgets")
.
Run this code to shim system.file
for htmlwidgets, and then load_all()
your widget package: https://gist.github.com/wch/c942335660dc6c96322f
shim_system_file <- function(package) {
imports <- parent.env(asNamespace(package))
pkgload:::unlock_environment(imports)
imports$system.file <- pkgload:::shim_system.file
}
shim_system_file("htmlwidgets")
shim_system_file("htmltools")
Of the two, I'd probably use the second since it's easier, maybe place it in a .Rprofile
to have it run at the start of every R session.
I've just learned there's an even easier solution though. The development versions of htmlwidgets and htmltools have system.file
shims built-in now, so load_all()
just works: https://github.com/ramnathv/htmlwidgets/pull/340. You can install the dev version of both like:
devtools::install_github("ramnathv/htmlwidgets")
And then just load_all()
your widget package as usual without further workarounds.
Upvotes: 1