Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - Rendering HTML widget in external browser

Tags:

html

r

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')
like image 445
Antoine Gautier Avatar asked Nov 27 '25 12:11

Antoine Gautier


1 Answers

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")
like image 58
Antoine Gautier Avatar answered Nov 30 '25 02:11

Antoine Gautier