We're currently developing an htmlwidget and we've wondered how to best iterate during development.
AFAIK, whenever I change the foo_widget.js
js binding (or any of the other inst/htmlwidgets
dependencies), I need to run R CMD Install
, so that the dependencies get copied over to the library.
Only then can I run my foo_widget()
function, and check out the results.
devtools::load_all()
works for foo_widget.R
, but not for the dependencies.
Needless to say, this is a bit cumbersome and takes too much time.
So I've used htmlwidgets::saveWidget(widget = "foo_widget", selfcontained = FALSE)
to write out a "testbed" foo_widget.html
.
I then move that foo_widget.html
over to the root of inst/htmlwidgets
, hack-fix all its dependency paths, and can then just open foo_widget.html
in a browser, or use something like atom to conveniently edit my css and js, and directly inspect the results.
This works well enough, but feels a little hacky, because all of the foo_widget()
options are now hard-coded into my HTML, and I can't quickly test several of those.
So my question is: Has anyone figured out a better way?
I was also considering to raise an issue at the htmlwidgets repo and ask them to do some black magic to recognize when devtools::load_all()
is being used (I think htmltools does something like this?), and change the paths accordingly.
But I wanted to make sure first, I was on the right track.
Curious how other people develop htmlwidgets.
I'm not great in JS, so I need to iterate a lot