Open stefangeorge opened 8 years ago
Pinging @JanSchulz and @flying-sheep as this question relates to the R kernel.
The problem is that we are not interactive:
In googleVis:::plot.gvis
[...]
print(x, file = file)
.url <- sprintf("http://127.0.0.1:%s/custom/googleVis/%s",
ifelse(R.version["svn rev"] < 67550 | getRversion() <
"3.2.0", get("httpdPort", envir = environment(startDynamicHelp)),
tools::startDynamicHelp(NA)), basename(file))
if (interactive()) {
browseURL(.url, ...)
}
else {
browseURL(.url, browser = "false", ...) # does basically nothing due to the false :-(
}
invisible(file)
This produces an iframe, but I can't get it to become visible:
repr_text.gvis <- function(obj, ...) 'gvis cannot be represented in plain text (need html)'
repr_html.gvis <- function(obj, ...){
htmlfile <- googleVis:::plot.gvis(obj)
readChar(htmlfile, file.info(htmlfile)$size)
}
# no plot, just let it display...
G
This works...:
repr_text.gvis <- function(obj, ...) 'gvis cannot be represented in plain text (need html)'
repr_html.gvis <- function(obj, ...){
if (!requireNamespace('googleVis', quietly = TRUE))
stop('repr_html.gvis called without loadable googleVis')
htmlfile <- tempfile(fileext = '.html')
on.exit(unlink(htmlfile))
print(obj, tag='chart', file=htmlfile)
readChar(htmlfile, file.info(htmlfile)$size)
}
repr_latex.gvis <- function(obj, ...) NULL
repr_markdown.gvis <- function(obj, ...) NULL
why not simply this?
repr_html.gvis <- function(obj, ...) {
if (!requireNamespace('googleVis', quietly = TRUE))
stop('repr_html.gvis called without loadable googleVis')
capture.output(print(obj, tag = 'chart'))
}
I added a PR to googleVIS to add these functions: https://github.com/mages/googleVis/pull/39
The interactive stuff is https://github.com/IRkernel/IRkernel/issues/236 :-(
why not simply this?
random choice (and having the htmlwidget code available): I don't like neither using a tempfile nor capture.output
:-) The real solution in this case would be to extract the string generation from print.gvis
and use that directly instead of having print first generate the string and then output it via cat and we then capture.output
/ read it in from the file.
Using this works in R console:
plot(G)
but when typed into a cell in jupyter I get:
starting httpd help server ... done and no graph.
So here is what I did. Into Anaconda 2.7.11, I installed R essentials
started up jupyter
installed needed reqs, XML and googleVIS, by typing this into a cell
typed this code into a cell
then
This code works fine when typed directly into an R console and makes a nice map. But something is causing jupyter to choke on starting a server. I guess since jupyter itself is web page running in a server there is some sort of problem with a web page starting a server? GoogleVIS needs to start the http do server that I think is built into R. But I don't know how to test whether this functionality exists in jupyter or the R essentials that I installed into Python.