[rkward] /: Add support for passing "htmlwidget" objects through rk.print().
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Jan 21 13:28:56 UTC 2016
Git commit c422a32265ea64d0133b72bd6a0bc00c6fa45e56 by Thomas Friedrichsmeier.
Committed on 21/01/2016 at 13:27.
Pushed by tfry into branch 'master'.
Add support for passing "htmlwidget" objects through rk.print().
This required supporting loads in subordinated frames of the output window.
M +1 -0 ChangeLog
M +14 -4 rkward/rbackend/rpackages/rkward/R/rk.print-functions.R
M +4 -0 rkward/windows/rkhtmlwindow.cpp
http://commits.kde.org/rkward/c422a32265ea64d0133b72bd6a0bc00c6fa45e56
diff --git a/ChangeLog b/ChangeLog
index 96dd806..c94aefd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- Add support for adding "htmlwidget"-class objects to the output window via rk.print()
- Add plugins for importing Excel files (.xls and .xlsx, Perl- and Java-based)
- Add ability to extract <matrix> values row-wise in plugins
- Add convenience JS-function "makeOption()" for use in plugins
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R
index 31e7931..775cdb2 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R
@@ -9,7 +9,8 @@
#' \code{rk.print} prints/exports the given object to the output (html) file
#' using the \code{\link{HTML}} function. This requires the \code{R2HTML}
#' package. Additional arguments in \code{...} are passed on to
-#' \code{\link{HTML}}.
+#' \code{\link{HTML}}. For some types of objects (e.g. "htmlwidgets" from
+#' the "htmlwidgets" package) additional packages may be required.
#'
#' \code{rk.print.literal} prints/exports the given object using a
#' \code{paste(x, collapse="\n")} construct to the output (html) file.
@@ -90,9 +91,18 @@
#'
#' @export
"rk.print" <- function(x,...) {
- htmlfile <- rk.get.output.html.file()
- if(require("R2HTML")==TRUE) {
- HTML(x, file=htmlfile,...)
+ if (inherits (x, "htmlwidget")) {
+ require ("htmlwidgets")
+ name <- deparse (substitute (x))
+ filename <- rk.get.tempfile.name (name, ".html")
+ dir <- rk.get.tempfile.name (name, "_data")
+ saveWidget (x, filename, selfcontained=FALSE, libdir=dir)
+ .rk.cat.output (paste0 ("<object width=\"100%\" height=\"100%\" data=\"file://", filename, "\" onload=\"this.style.height = this.contentWindow.document.body.scrollHeight + 'px';\"></object>"))
+ } else {
+ htmlfile <- rk.get.output.html.file()
+ if(require("R2HTML")==TRUE) {
+ HTML(x, file=htmlfile,...)
+ }
}
}
diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index b5ecbf5..4ab5f86 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -95,6 +95,10 @@ bool RKWebPage::acceptNavigationRequest (QWebFrame* frame, const QNetworkRequest
return false;
}
+ if (frame != mainFrame ()) {
+ if (request.url ().isLocalFile () && (KMimeType::findByUrl (request.url ())->is ("text/html"))) return true;
+ }
+
if (KUrl (mainFrame ()->url ()).equals (request.url (), KUrl::CompareWithoutFragment | KUrl::CompareWithoutTrailingSlash)) {
RK_DEBUG (APP, DL_DEBUG, "Page internal navigation request from %s to %s", qPrintable (mainFrame ()->url ().toString ()), qPrintable (request.url ().toString ()));
emit (pageInternalNavigation (request.url ()));
More information about the rkward-tracker
mailing list