danielkrizian / rChartsDygraphs

An `rCharts` extension. Run `dygraphs` from R - interactive visualizations of time series using JavaScript and HTML canvas. See: http://dygraphs.com/ and
http://rcharts.io/
9 stars 10 forks source link

Show multi-chart layout in the RStudio viewer #1

Closed danielkrizian closed 10 years ago

danielkrizian commented 10 years ago

Refactor layout to open in RStudio viewer.

layout_dygraphs(dy1, dy2) currently opens separate web browser window:

layout_dygraphs <- function(...) {
  l = list(...)
  showCharts = if(length(l)==1 & is.list(l)) l[[1]] else l
  outfile <- file.path(tempdir(),"tmp.Rmd")
  brew(system.file('libraries/dygraph/layouts/multi.Rmd', package = 'rChartsDygraph'), outfile)
  browseURL(knit2html(outfile, outfile))
}

https://github.com/danielkrizian/rCharts_dygraphs/blob/master/R/Dygraph.R#L120-L126

executable demo here: https://github.com/danielkrizian/rCharts_dygraphs/blob/master/examples/multi-layout.R

Can we get rid of writing the knit-ed html to outfile and instead pass on-the-fly to the viewer?

Some thoughts: show method for the layout mode, a la: https://github.com/ramnathv/rCharts/blob/master/R/rChartsClass.R#L105-L129

timelyportfolio commented 10 years ago

I'll take a shot at it tonight or tomorrow morning. I don't expect too much difficulty, but as usual will probably find it harder than it seems :)

timelyportfolio commented 10 years ago

Having trouble submitting a pull request since this is a forked version of mine, but I did a first pass at this in the view_rstudio branch of my original repo in these lines. It works, but will need some iteration for robustness. Most of it is copied from rCharts show.

Eventually, I think it would be very nice to add a full set of layout options using something like bootstrap grids, but I'll save that for a later branch.

danielkrizian commented 10 years ago

ok since your pull request didn't work, will manually integrate the diffed lines from your fork's view_rstudio branch to danielkrizian/rChartsDygraphs/master (assuming this is correct destination), so that we can all work from a single repo

danielkrizian commented 10 years ago

I copied over your lines and ran demo, but getting this error:

layout_dygraphs(dygraph1, dygraph2) Error in dir.create(temp_dir) : object 'temp_dir' not found

See commit inline notes: https://github.com/danielkrizian/rChartsDygraphs/commit/42598dbe06480b631e49d40e25aa487ee0b5c770

Does it work on yours, after clean install? (temporary mess with repository renaming)

TonyDIRL commented 10 years ago

I can confirm the same 'temp_dir' issues on a linux box, after a clean install

danielkrizian commented 10 years ago

Ok works now, added these lines in the correct if branch. @TonyDIRL you can test by running examples/multi-layout.R. Thanks @timelyportfolio, learnt from your code how to replace .Rmd templating with .html+whisker templating. If you have further ideas how to progress this (any good tutorial about bootstrap grids for https://github.com/danielkrizian/rChartsDygraphs/issues/6 ), let me know!

timelyportfolio commented 10 years ago

funny, I was just working on this. Your fix works on my end. Well done. I hope to play with #6 in the next couple of days.