# This is imperative, especially the local = FALSE. # We need to ensure that gdk_pixbuf_new() is available # to the pixbuf loader libraries (for jpeg, gif, xpm, etc.) # which are dynamically loaded by the Gtk libraries (specifically GtkHTML). # However, these loader libraries are not linked against libgdk_pixbuf # and so expect to find the symbols from that library in the host # application. This doesn't happen in R unless we explicitly put # the symbols there using dyn.load(, local = FALSE). # The configuration of the RGtk package (or specifically the GtkHTML part # of it) needs to find libgdk_pixbuf on the system and put that into the # R code. # # It would be better to do this downloading, reading and writing to the GtkHTMLStream # using connections and avoiding the file system. dyn.load("/usr/lib/libgdk_pixbuf.so", local = FALSE) htmlLoadImage <- function(w, url, stream, ...) { # see if there is a protocol in the URL separated from the # file name by a `:' x <- strsplit(url, ":")[[1]] if(length(x) > 1 && x[1] != "file") { # so there is a protocol tmp <- tempfile() if(download.file(url, destfile = tmp)) { stop(paste("Cannot download URL", url)) } url <- tmp } else { if(x[1] == "file") url <- x[2] if(length(grep("^/", url)) == 0) { dir <- dirname(w$GetBase()) if(nchar(dir)) url <- paste(dir, url, sep=.Platform$file.sep) print(url) } } .Call("R_readFileToHTMLStream", as.character(url), stream, TRUE, PACKAGE="RGtk") } # From the RGtkViewers package. x <- viewHtml("") x$html$AddCallback("url_requested", htmlLoadImage) x$load("test2.html")