[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] capture htmlwidgets for export - a pattern in search of a new :resul
From: |
Cook, Malcolm |
Subject: |
[O] capture htmlwidgets for export - a pattern in search of a new :results type??? |
Date: |
Tue, 28 Jul 2015 19:29:34 +0000 |
I have been playing with exporting htmlwidgets [1] generated in R code-blocks.
[1] http://www.htmlwidgets.org/ and
Here is a worked example that exports to html
#+BEGIN_SRC R :session *R* :exports both :results html
library(htmlwidgets)
library(d3heatmap)
widget<-d3heatmap(mtcars, scale="column", colors="Blues")
saveWidget(widget,'d3heatmap_widget.html')
print('<iframe height=700px width=700px
src=./d3heatmap_widget.html></iframe>')
#+END_SRC
#+RESULTS:
#+BEGIN_HTML
<iframe height=700px width=700px src=./d3heatmap_widget.html></iframe>
#+END_HTML
After doing a few of these, a pattern emerges: using ':results html' in the
code bock header, and the last 2 lines of:
saveWidget(...)
print('<iframe ... ')
I think this pattern motivates considering developing support for "htmlwidget"
as a new :results type (in addition to 'raw, org, html, latex, code, pp,
drawer')
It could be used in combination with :file and understood by the R/org "glue"
and exporters.
Allowing to write, instead of the above, something like:
#+BEGIN_SRC R :session *R* :exports both :file d3heatmap_widget.html
:results htmlwidget :height 700 :width 700
library(htmlwidgets)
library(d3heatmap)
d3heatmap(mtcars, scale="column", colors="Blues")
#+END_SRC
#+RESULTS:
file: d3heatmap_widget.html
The org-to-R glue would have to behave somewhat similarly to how graphics are
currently handled, however, instead of "printing" the value to the :file, the
value would need to be saveWidget-ed.
And, similar to image handling, the exported value would be "in-lined" into the
html, wrapped in an iframe (I presume).
Perhaps there is a better or more useful abstraction.
Or a better workaround than simply following the pattern when needed (which is
not too hard anyway).
Any ideas along these lines?
Thanks
Malcolm Cook
address@hidden
- [O] capture htmlwidgets for export - a pattern in search of a new :results type???,
Cook, Malcolm <=