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

Shiny integration #4

Open danielkrizian opened 10 years ago

danielkrizian commented 10 years ago

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?

timelyportfolio commented 10 years ago

I believe renderChart2 will work fine. As far as I can tell, the issue is with chartOutput which uses rCharts get_lib which does not allow for other packages in the system.file(...,package="rCharts"). I will update my fork of rCharts referenced in the readme to allow an option for other packages. I'll check with @ramnathv to see if there are any issues with this on the rCharts side.

timelyportfolio commented 10 years ago

I think this is more of an rCharts issue for single plots, so changed my dimple_layer branch of rCharts. To see it work, see this mini repo. Where we will need to make changes in this repo will be the layout_dygraphs for multiple charts. I'll explore this here.

ramnathv commented 10 years ago

Great work @danielkrizian and @timelyportfolio! I have been out-of-action with rCharts, but will pick up stuff starting next week. Focus will be to clean up existing code, incorporating all the pull requests and merging dev with master. Once I get that done, I will work on making the changes to get Shiny working with packages depending on rCharts.

timelyportfolio commented 10 years ago

@ramnathv changes required were minimal with commit-get_lib and commit-chartOutput . If you deem ok, they will get pulled with the dimple_layer branch.

ramnathv commented 10 years ago

Perfect. I think that should do the trick. I will just do a quick scan of any other places where get_lib is being called, so that we can update its signature.

TonyDIRL commented 10 years ago

@timelyportfolio I've tested the shiny - rcharts - dygraph example and can confirm it works - awesome.

Interestingly, on a windows machine running the shiny example on a shiny server causes several repaint issues with dygraph - essentially, several datapoints remain as residuals in the plot.

However, running the app locally with runApp() and had no such issues. Perhaps, isolated to my machine but would be interesting if other users have the same problem.

Thanks again - great to combine these tools.

timelyportfolio commented 10 years ago

I just realized that I was using dimple_layer locally, and that I never sent a pull request to @ramnathv for rCharts, so the change was not picked up. I have isolated these changes and sent a new pull request.

TonyDIRL commented 10 years ago

Hi,

I appreciate the following problem may have multiple roots but I thought I'd start here and see if the problem can be reproduced. As mentioned previously, on a windows machine running the example on a shiny server causes several repaint issues with dygraph after zooming and panning - essentially, several datapoints remain as residuals in the plot.

image

However, running the app locally with runApp() has no such issues. Perhaps, isolated to my setup but would be interesting if others can reproduce the same problem.

danielkrizian commented 10 years ago

Thanks @TonyDIRL. To reproduce, can you possibly share/link your code somehow (maybe through your forked repo)? That would be helpful for (diff) analysis

timelyportfolio commented 10 years ago

I experience the same issue on my Windows machine. I will try to debug it.

TonyDIRL commented 10 years ago

@danielkrizian - this problem seems specifically related to shiny-server. runApp() and runGist() do not seem to have repainting issues.

TonyDIRL commented 10 years ago

Hi @timelyportfolio , was wondering if you had an opportunity to debug the repainting issues with dygraph on a shiny server?

timelyportfolio commented 10 years ago

Looked more at this tonight. Strange but it only occurs for me in Chrome. Seems to work fine for me in RStudio browser and IE. I'll keep trying to figure this out.

timelyportfolio commented 10 years ago

Ok, by inspecting the elements I think I am one step closer. When I change all of the canvasses to have height = 1000 and width = 400 and then gs[0].updateOptions({}) to refresh, it all works nicely. Now, I just need to see where the improper sizing takes place and why it is different in Chrome. Anybody have any ideas?

Chrome

image

IE

image

TonyDIRL commented 10 years ago

Thank you @timelyportfolio for debugging. I tried in firefox previously but had similar issues to Chrome. Interestingly, the issue is inconsistent in Chrome - on occasion the correct canvas sizes are generated.

I've very little knowledge of html so I've posted this query on the Shiny google group so hopefully we will get some feedback there.

timelyportfolio commented 10 years ago

Quick update:

I made an app without Bootstrap, and I can confirm that Bootstrap is not causing the problem, so my first suspicion did not correct anything.

timelyportfolio commented 10 years ago

Calling all testers (@tonyDIRL)

Not at all what I thought. Error on my side comes in here. Somehow my Chrome was zoomed to 90%, and that caused the issue. When I CTRL+0 to return to 100% or manually overrode the scales with canvasScale=1 and hiddenScale=1, everything worked fine. I am not sure we need to change anything if this is the case. I guess we could consider skipping or modifying the canvasScale check. We might file an issue over at dygraphs.

Note: when I set zoom to something less than 100% in IE, I get the same issue.

TonyDIRL commented 10 years ago

Nice work. @timelyportfolio. I can confirm across multiple machines and browser versions it is a zooming issue. Nice find - I was digging around this without success for quite a while.

Were you able to manually override the canvasScale=1 and hiddenScale=1 with some JS from within R?

I'll log the issue with dygraphs.

danielkrizian commented 10 years ago

@pshevtsov , could you send a pull request to danvk please? I think the simplest reproducible case we have right now is https://github.com/timelyportfolio/rCharts_dygraphs_shiny/, or can this case be further stripped down to pure JavaScript?

timelyportfolio commented 10 years ago

Actually, the tests included in dygraphs experience this same bug. For instance, set browser zoom to <100% and open zoom.html. You should see the same bug.

danielkrizian commented 10 years ago

Strange, to me the graph behaves correctly even when I zoom Chrome (Windows 7):

http://rawgit.com/danvk/dygraphs/master/tests/zoom.html

image

timelyportfolio commented 10 years ago

To get the error zoom < 100 then refresh.

danielkrizian commented 10 years ago

Ok, I see now (clicking refresh is needed). Thanks, well isolated