R - Rendering HTML widget in external browser - html

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/

Related

Save chromomap plots in base R

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!

How to export htmlTable from the viewer to a word document in R

I'm working with the htmlTable function. While the table renders perfectly in the R studio viewer, I am unable to save, copy and paste, or screenshot it, such that it looks equally nice in the word document I am writing. I was wondering if there was a way for me to export or save the image, such that the table show up just as nice in the word document.
Here is an example table.
output <-
matrix(paste("Example", LETTERS[1:16]),
ncol=4, byrow = TRUE)
library(htmlTable)
htmlTable(output)
You can display your table as grid graphics using grid.table function from gridExtra library. And save it as image using ggsave function from ggplot library.
library(ggplot2)
library(gridExtra)
ggsave(grid.table(output), filename = "~DirectoryName/imageName.png")

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.

why my qt webView can't return html

all
a few days ago,i use wxpython want to access ie. but i don't know how to use activex ie with python. my question link how use IEHtmlWindow widget change html form
so i use pyQt to develop GUI program.
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.webView = QtWebKit.QWebView(self.centralwidget)
self.webView.setGeometry(QtCore.QRect(110, 30, 571, 231))
self.webView.setUrl(QtCore.QUrl(_fromUtf8("about:blank")))
self.webView.setObjectName(_fromUtf8("webView"))
self.webView.load(QUrl('http://zzxh.zjsgat.gov.cn:6081/zjwwzzxh/'))
frame = self.webView.page().mainFrame()
print unicode(frame.toHtml()).encode('utf-8')
i run front code. but it's also return following result
<html><head></head><body></body></html>
i think i know why it's always return '' , besause .toHtml() method must need the page load success.

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")