Giter Site home page Giter Site logo

danielkrizian / rchartsdygraphs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timelyportfolio/rcharts_dygraphs

9.0 9.0 10.0 15.07 MB

An `rCharts` extension. Run `dygraphs` from R - interactive visualizations of time series using JavaScript and HTML canvas. See: http://dygraphs.com/ and

Home Page: http://rcharts.io/

R 10.93% CSS 0.10% JavaScript 88.96%

rchartsdygraphs's People

Contributors

danielkrizian avatar jangorecki avatar przmv avatar timelyportfolio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rchartsdygraphs's Issues

Show multi-chart layout in the RStudio viewer

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

Layouts using Shiny

My apologies to be late to the party on layouts, but I got this inspiration just last night. Shiny has a full fledged HTML DSL for R that can be taken advantage of directly. Here is a simple example using the Shiny DSL to create two plots.

We first create two plots using rCharts. We set the width of all charts to 550 so that we can fit two in one column.

library(rCharts)
options(RCHART_WIDTH = 550)
r1 <- rPlot(mpg ~ wt, data = mtcars, type = 'point')
r2 <- rPlot(mpg ~ wt, color = 'am', data = mtcars, type = 'point')

Second, we write a small helper function that saves the chart html (just the div + script) as a character and runs it through shiny's HTML function to take care of escaping.

library(shiny)
rChart = function(x, id){
  x1 = paste(capture.output(x$print(id)), collapse = '\n')
  HTML(x1)
}

Next, we create a HTML page with the two charts using Shiny's DSL. Note that currently I am injecting the js/css assets manually, but it should be trivial to write a script that would do this automatically based on the library being used.

page = with(tags, html(
      link(href="http://netdna.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css", rel="stylesheet"),
      script(src="http://ramnathv.github.io/rCharts/libraries/widgets/polycharts/js/polychart2.standalone.js"),
  fluidRow(
    column(6, 
      rChart(r1, 'chart1')    
    ),
    column(6,
     rChart(r2, 'chart2')
    )
  )   
))

Finally, we save the generated HTML to a a tempfile and use the rstudio viewer to view it.

tf <- tempfile(fileext = ".html")
writeLines(as.character(h), con = tf)
rstudio::viewer(tf)

The nice thing about this approach is that it is very generic and we can take advantage of Shiny.

Let me know what you guys think. If you see value in this approach, I can abstract it out and create some wrappers within rCharts.

Add `data.table` as dependency?

When I was trying to install rChartsDygraphs with

> install_github('rChartsDygraphs', 'danielkrizian')

command, I got the following error message:

** preparing package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  there is no package called 'data.table'
ERROR: lazy loading failed for package 'rChartsDygraphs'
* removing '/home/petr/R/x86_64-pc-linux-gnu-library/3.0/rChartsDygraphs'
Error: Command failed (1)

So, I had to manually install data.table package:

> install.packages("data.table")

Shiny integration

try to work on the shiny integration by implementing what is in rCharts and maybe improving by having a look at ggvis.
Can we use renderChart2 from other rCharts libraries?

french_industry.csv file compress

Hi,
You may make your package little more portable by gzip'ing the french_industry.csv file. R natively support csv.gz files so there is not trade-off because of that. Alternatively Rdata/rds files. csv files have usually good compression rate. Currently every time you want to fetch updates from github by install_github you need to download 12MB csv.
Regards,
Jan

Error in the Example

I am new to rCharts and I ran through the example. I got the following error:

> dygraph(data=dydata, ribbon=colors)
> dygraph(data=dydata, ribbon=list(colors=ribbon, height=0.2, pos=0.1))
Error in dygraph(data = dydata, ribbon = list(colors = ribbon, height = 0.2,  : 
  object 'ribbon' not found

There's indeed no variable called ribbon. How can I get it? Thank you.

P.S.: My environment:

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936 
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936   
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[4] LC_NUMERIC=C                                                   
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] data.table_1.9.2    quantmod_0.4-0      TTR_0.22-0          Defaults_1.1-1     
 [5] rChartsDygraphs_0.2 xts_0.9-7           zoo_1.7-11          brew_1.0-6         
 [9] rCharts_0.4.2       knitr_1.6           slidify_0.4.5      

loaded via a namespace (and not attached):
 [1] codetools_0.2-8 digest_0.6.4    evaluate_0.5.5  formatR_0.10    grid_3.1.0      lattice_0.20-29
 [7] markdown_0.7    plyr_1.8.1      Rcpp_0.11.2     reshape2_1.4    RJSONIO_1.2-0.2 stringr_0.6.2  
[13] tools_3.1.0     whisker_0.3-2   yaml_2.1.11    

Decimal Point Precision

Perhaps I'm missing something obvious but I can't get beyond two decimal points of precision on y-axis variables.

getSymbols("SPY", from = "2014-01-01")
mychart=dygraph(SPY$SPY.Open+0.0025)
mychart$setOpts(drawPoints=TRUE,digitsAfterDecimal= 5,yaxisLabelWidth= 5)
mychart

The relevant dygraph parameters are digitsAfterDecimal, yaxisLabelWidth and a custom yaxisLabelFormatter function as can be seen in this jsfiddle:
http://jsfiddle.net/TonyDIRL/fGZ2D/

Reviewing the generated source from the above R code shows

..."SPY.Open": [ 183.98, 183.23,

I've walked through the parseData function within the library but I can't see where the explicit rounding occurs.

Please advise.

shiny rChartsDygraphs integration

I'm trying to put dygraphs inside the shiny application.
When trying to render graph as usually in shiny/rCharts I get following error in js console dygraphs: Constructing dygraph with a non-existent div! which reffers to dygraph.js#L422

I found this repo: timelyportfolio/rCharts_dygraphs_shiny
which simply uses renderChart_nosize function, its body looks quite mysterious for me. Anyway it plots the dygraph in shiny application but it lose the zooming capability also it do not scale to appropriate height and width (which can be seen in the _nosize function body). All these makes @timelyportfolio workaround less useful.

Is there any better way to integrate rChartsDygraphs into shiny?

dygraph: trades argument

Hi,
Would it be possible to extend functionality of trades argument in dygraph to accept other kinds of signals?
It's current structure is quite specific, I would prefer to just pass entry/exit index positions to be plotted.
Additionally as far as I understand the current trades is limited to plot only closed positions, user cannot plot an entry point if that point haven't got exit yet.
Is this currently used trades object any kind of popular structure for storing entry/exit stats?

Continuous red ribbon problem

I use the following code to try the ribbon feature:

getSymbols("SPY", from = "2001-01-01")
difference = SPY[,"SPY.Open"]-SPY[,"SPY.Close"]
decreasing = which(difference<0)
increasing = which(difference>0)

colors = rep("transparent", nrow(dydata))
colors[decreasing] = "red"
colors[increasing] = "green"

dydata=SPY[,"SPY.Close"]
dygraph(data=dydata, ribbon=list(colors=colors, height=0.05, pos=0.02))

The result looks like:
1.png

I zoomed in:
2.png

Notice the last part of the ribbon stays red.

I tried to change the height and pos of ribbon but didn't help.

This appears in my firefox, chrome and RStudio viewer.

Demo Issue / Millisecond Plotting / Integration with Shiny

Hi,

First off, cheers for working on this package - great for someone like myself with R exposure but little JS experience to get access to the plotting power of dygraph.

With regards the initial demo - the new branch resolves some of the issues. Specifically, dygraph1 and dygraph2 will now both individually render correctly, However, layout produces a blank page and layout_dygraphs seems to skip Rstudio and goes directly to the browser with the same effect. Strangely, either function does not produce a html output.

On a different note, how would I go about plotting millisecond resolution on the x-axis?
I'm aware for other rchart libraries such as highcharts the following is required
paste("#!", as.numeric(....timestamps....)"!#")
However, this does not seem to work for dygraph?

Finally, is it possible to integrate dygraph with Shiny? I'm aware that for other rchart libraries renderChart2 can be used but this does not seem to support dygraph as of yet - would be really cool if it did.

Thanks again and happy to help out anyway I can.

`width/height` cleanup & defaults to fit RStudio viewer

Dimensions of the charts are fixed and do not fit RStudio viewer:

image

Moreover, resolve trifold conflict where width and height are specified:

    <style>
    .rChart {
      display: block;
      margin-left: auto; 
      margin-right: auto;
      width: px;
      height: px;
    }  
    </style>

      </head>

      <body>
        <script>
          var blockRedraw = false;
          var gs = [];
        </script>


    <div id = 'chart401849fb2b17' class = 'rChart dygraph'></div>
    <script>
      if (typeof gs === 'undefined') { var gs = [] };
      if (typeof blockRedraw === 'undefined') { var blockRedraw = false };
      (function(){
        var params = {
     "dom": "chart401849fb2b17",
    "width":    800,
    "height":    400,
        "options": {
         "width":   1000,
        "height":    400,

@timelyportfolio let me know if any ideas

Error in get_assets using the branch: "dimple_layer" in R 3.1 and RStudio (last version)

Hi, this packages seems great :) I use rChart in my daily research in Economics, I think I'll use this package soon :).

Anyway... My problem is related to this error message

"Error in get_assets(LIB, static = static, cdn = cdn, standalone = standalone) :
unused argument (standalone = standalone)"

So I tried to investigate in Internet, I found this: In the line 86 https://github.com/ramnathv/rCharts/blob/master/R/rChartsClass.R
there is this option. (in TimelyPortfolio also)

When I used rChart (ramnathv repo), I don't have any error message. However I can't display the data in a correct way...

There is something different in dimple_layer https://github.com/timelyportfolio/rCharts/blob/dimple_layer/R/rChartsClass.R
Now is in line 89

I'm going to investigate harder in 3 weeks.

Thank in advance and nice work

This is my session Info

R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Spanish_Peru.1252
[2] LC_CTYPE=Spanish_Peru.1252
[3] LC_MONETARY=Spanish_Peru.1252
[4] LC_NUMERIC=C
[5] LC_TIME=Spanish_Peru.1252

attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base

other attached packages:
[1] quadprog_1.5-5 FactorAnalytics_0.3
[3] PerformanceAnalytics_1.1.0 gdata_2.13.3
[5] rChartsDygraphs_0.2 rCharts_0.4.2
[7] rjson_0.2.14 devtools_1.5
[9] data.table_1.9.2 quantmod_0.4-0
[11] TTR_0.22-0 Defaults_1.1-1
[13] xts_0.9-7 zoo_1.7-11
[15] knitr_1.6 brew_1.0-6

loaded via a namespace (and not attached):
[1] digest_0.6.4 evaluate_0.5.3 formatR_0.10
[4] grid_3.1.0 gtools_3.4.1 httr_0.3
[7] lattice_0.20-29 markdown_0.6.5 memoise_0.1
[10] parallel_3.1.0 plyr_1.8.1 Rcpp_0.11.1
[13] RCurl_1.95-4.1 reshape2_1.2.2 RJSONIO_1.0-3
[16] slidify_0.4.5 stringr_0.6.2 tools_3.1.0
[19] whisker_0.3-2 yaml_2.1.11

dygraph and polygon

Hi,
Is it possible to make polygon plot in dygraphs?
I would like to achieve following effect:

  • yellow line in the middle is my vwap (can be also close price, doesn't matter).
  • red polygon below the line is the area between vwap and low.
  • green polygon above the line is the area between vwap and high.

examples:

image and image

Currently what I can do is just to plot straight line low/high as another series.
If it's possible, could you expand the examples for it?
Regards

Repo rename `rCharts_dygraphs` to `rChartsDygraphs` ?

@timelyportfolio , @ramnathv
if no objections, I will rename the whole repository from rCharts_dygraphs to rChartsDygraphs (without dash)

This is because:

  • to match the current, after-installation name of the package
  • to match convention @ramnathv started
  • R packages cannot contain _ symbols

EDIT: new name rather rChartsDygraphs, to reflect the name of the original JS library (dygraphs). Sorry for confusion

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.