Save chromomap plots in base R - html

I am using Chromomap in base R in a cluster (not with Rstudio). Could you please tell me if It is possible to save the plots in base R?
I tried with something like this:
library(chromoMap)
jpeg("CHR.jpg", width=4000, height= 6000)
chromoMap("chromosome_file.txt","anno.txt", data_based_color_map = T, data_type = "numeric")
dev.off()
But didn´t work. I think that chromomap is supposed to produce an HTML in Rstudio. Suggestions?

I am afraid it is not possible (same issue here!). I solved using karyoploteR. I am still working to prettify the output, but I am satisfied, and it allows saving pdf or jpeg of the graph.
Other suggestions are welcome!

Related

splinter nested <html> documents

I am working on some website automation. Currently, I am unable to access a nested html documents with Splinter. Here's a sample website that will help demonstrate what I am dealing with: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select
I am trying to get into the select element and choose the "saab" option. I am stuck on how to enter the second html document. I've read the documentation and saw nothing. I'm hoping there is a way with Python.
Any thoughts?
Before Solution:
from splinter import Browser
exe = {"executable_path": "chromedriver.exe"}
browser = Browser("chrome",**exe, headless=False)
url = "https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select"
browser.visit(url)
# This is where I'm stuck. I cannot find a way to access the second (nested) html doc
innerframe = browser.find_by_name("iframeResult").first
innerframe.find_by_name("cars")[0]
Solution:
from splinter import Browser
exe = {"executable_path": "chromedriver.exe"}
browser = Browser("chrome",**exe, headless=False)
url = "https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select"
browser.visit(url)
with browser.get_iframe("iframeResult") as iframe:
cars = iframe.find_by_name("cars")
cars.select("saab")
I figured out that these are called iframes. Once I learned the terminology, it wasn't too hard to figure out how it interact with it. "Nested html documents" was not returning the results I needed to find the solution.
I hope this helps someone out in the future!

Saving R timevis timeline in html webpage

I'm sure I'm missing a basic issue but I'm not currently able to find my way out of this problem.
Is there a way to save a simple (not Shiny) Timevis timeline in html webpage from the code?
I've successfully tried by using RStudio export button but I would like to include the function in the code.
htmlwidgets::saveWidget() doesn't work properly as the webpage is incomplete e.g. zoom buttons are missing (see incomplete webpage print screen) even with a minimal code:
myTimeline<-timevis(
data.frame(id = 1:2,
content = c("one", "two"),
start = c("2016-01-10", "2016-01-12"))
)
htmlwidgets::saveWidget(myTimeLine,"myTimeLine.html")
Thank in advance for any help and advice!
There is an open issue on github about this.
The workaround is to use selfcontained = FALSE:
htmlwidgets::saveWidget(myTimeline, "myTimeLine.html", selfcontained = F)
If you want to use a selfcontained version (e.g. because you want to offer this htmlwidget via plumber), the issue is the lack of zoom buttons.
If you modify the output HTML content to re-include the zoom buttons properly, everything works fine.

Scraping in R, cannot get "onclick" attribute

I'm scraping the NFL website with R. R might not be the best to do this but that is not my question here.
I can usually get everything I want but for the first time I got a problem.
In the present case I want to get info from let's say, this page
http://www.nfl.com/player/j.j.watt/2495488/profile
The info I want to get is there
Draft
Using xPathSapply(parsedPage,xmlGettAttr, name="onclick") I get only NULL... and I do not get the reason why.
I could retrieve the information elsewhere in the code and then paste to recover the address but I find it much easier and clearer to get it at once.
How can I get this, using R, eventually C. I do not know much about JavaScript, I would be happy to avoid this.
Thanks in advance for the help.
The reason is that there are no "onclick"-attributes in the sourcecode: See (in Chrome)
view-source:http://www.nfl.com/player/j.j.watt/2495488/profile
The onclick-attributes are added via javascript. Because of that you need a parser that executes the JS.
In R you can you RSelenium for that as follows:
require(RSelenium)
RSelenium::startServer()
remDr <- remoteDriver()
remDr$open()
remDr$navigate("http://www.nfl.com/player/j.j.watt/2495488/profile")
doc <- remDr$getPageSource()
require(rvest)
doc <- read_html(doc[[1]])
doc %>% html_nodes(".HOULink") %>% xml_attr("onclick")
remDr$close()
#shutdown
browseURL("http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer")
For me this resulted in:
[1] "s_objectID=\"http://www.nfl.com/teams/houstontexans/profile?team=HOU_1\";return this.s_oc?this.s_oc(e):true"
[2] "s_objectID=\"http://www.houstontexans.com/_2\";return this.s_oc?this.s_oc(e):true"
[3] "s_objectID=\"http://www.nfl.com/gamecenter/2015122004/2015/REG15/texans#colts/watch_1\";return this.s_oc?this.s_oc(e):true"
...
You can also use a headless browser like phantomjs see https://cran.r-project.org/web/packages/RSelenium/vignettes/RSelenium-headless.html

R - Rendering HTML widget in external browser

How could I render a HTML widget (produced by dygraphs in my case) directly in an external browser (Chrome for instance)?
I guess I could save the widget, build a HTML page, link the widget to it and use something like browseURL.
I am looking for something more seamless and performance oriented. The equivalent of the "Show in new window" button within R Studio viewer would be perfect (but without having to render the graph in R Studio viewer in the first place).
-- EDIT
Thanks for your suggestion Tan. I have tried with Markdown, seemed simpler than Shiny. But it did not work. Any idea why? (I get a strange "!–html_preserve–" flag in output).
require(data.table)
require(knitr)
require(dygraphs)
dt = data.table(
ts = as.POSIXct( c('2010-01-01','2010-01-02','2010-01-03') ),
value=rnorm(3)
)
write( "```{r}\n dygraph(dt) \n```", file = "tmp.Rmd" )
knitr::knit2html('tmp.Rmd')
browseURL('tmp.html')
Thanks to Jonathan from RStudio for his answer here.
require(data.table)
require(rmarkdown)
require(dygraphs)
dt = data.table(
ts = as.POSIXct( c('2010-01-01','2010-01-02','2010-01-03') ),
value=rnorm(3)
)
write( "```{r}\n dygraph(dt) \n```", file = "tmp.Rmd" )
rmarkdown::render("tmp.Rmd")
browseURL("tmp.html")
You are looking for Shiny, not quite HTML but fits the bill in every other way. http://shiny.rstudio.com/

Using knitr (from .Rhtml to html): how to embed a link in an R Figure?

I am using knit to convert my .Rhtml file to an .html file.
I am calling the output of a chunk called Q1:
<!--begin.rcode Q1,echo=FALSE,fig.show="all",fig.align="center",warning=FALSE
end.rcode-->
Here comes the chunk, it is basically a ggplot2 figure in a 2x2 layout.
library(ggplot2)
myplot = list()
for (i in 1:4){
x = 1:100
y = sample(100,100)
data = data.frame(x=x,y=y)
myplot[[i]] = ggplot(data,aes(x=x,y=y))+geom_point()+labs(title="bla")}
do.call(grid.arrange,c(myplot,list(nrow=2,ncol =2)))
Now, when looking at the resulting html file, I would like to incorporate the following feature:
I would like to have a link (e.g. to a database) when clicking on the title of each plot.
Is this somehow possible?
Thx
This doesn't completely answer your question, but it might get you or someone else started on a full answer.
Paul Murrel's gridSVG package (see also this useful pdf doc) allows one to add hyperlinks to grid-based SVG graphics. (In theory it should thus work with ggplot2; in practice I've just got it working with lattice). The current issue of the R Journal includes a couple of articles ("What's in a name?" and "Debugging grid graphics." -- Warning: pdfs) that might help you to best design dynamic searches for name of the grob to which you'd like to add a link (as in my second line of code).
library(gridSVG)
library(lattice)
xyplot(mpg~wt, data=mtcars, main = "Link to R-project home")
mainGrobName <- grep("main", grid.ls()[[1]], value=TRUE)
grid.hyperlink(mainGrobName, "http://www.r-project.org")
gridToSVG("HyperlinkExample.svg")