lageIBUSP / Rsampling

R package to reproduce the Resampling Stats Add-in
2 stars 9 forks source link

animated graphic? #8

Closed adalardo closed 9 years ago

adalardo commented 9 years ago

I was wondering if is not more easy include the graphic animation in the Rsampling package not in the shiny UI? For me, the best would be have a table animation, like in Excel plugin, showing the permutation running. But at least we can have a animated graphic for the statistic of interest (I am sure we can make something like Resampling, but I do not have the answer yet!). I thinking in work in a basic animation (similar to vegas.r and similar in the R course) but based in "Grid" package. The "grid" package is the base for lattice and ggplot2 graphics packages. I think it will be faster! One advantage to put the animated graphic in the Rsampling is we can build the animation during the permutation... not after. So the user can have some movie to watch!

andrechalom commented 9 years ago

I'm not sure what should the "animation" be, in terms of R objects. If they are to be passed between the base package and whichever interface we use, we should try to encapsulate the entire animation in a single object. Can we do that with grid objects? The documentation doesn't look very helpful in this case...

vrios commented 9 years ago

Just a quick thought, and probably not a very good ideia in terms of object encapsulation, but is it possible to do something like passing the original data by reference to the permutation function? If so, every time a data point changes position, the plot and the table can be animated by simply redrawing the plot, perhaps by redrawing it every x miliseconds, or by the equivalent of an event (i don't know if shiny allows something like messaging between objects).

This would have the advantage that it wouldn't be necessary to wait for the whole permutation to end before passing it to the interface and only then displaying it, it would be real-time, and it would still me pretty much interface-independent. It also has the advantage of keeping all the visual code (graphs, tables, and the like) in the interface, and all the permutation logic separate in the Rsampling package.

andrechalom commented 9 years ago

Pass-by-reference is not possible in "base" R, but we can do it using the data.table package. I'm not sure how shiny or Qt would interact with data.tables, however.

EDIT: it seems that there IS a way of dealing with pass-by-reference in base R, using the fact that environments are weird animals, see http://www.stat.berkeley.edu/~paciorek/computingTips/Pointers_passing_reference_.html

vrios commented 9 years ago

Qt would not be able to interact with it, unless using something like Rinside (http://dirk.eddelbuettel.com/code/rinside.html), perhaps on future versions of Qpermuta.

I found package ref http://cran.r-project.org/web/packages/ref/index.html which appears to provide "reference wrapper" functions to simulate pass-by-reference without needing to alter the original data structure, if it works like it seem to, it would be a better idea, as it would only be necessary to change the call to Rsampling. if the shiny plot/table is reactive, it might not even be necessary to alter the code to animate the results

adalardo commented 9 years ago

I don't know if I fully understand the idea of PASS_BY_REFERENCE, but "grid" graphics system works with independent viewports in a graphic device. Each of them can have other viewports in a hierarchical structure called viewport tree. Each viewport is a object and we can update its branch independent of others.

piklprado commented 9 years ago

Still, I think that animation is a feature for the Rsampling-shiny, because I see Rsampling as an engine and aslo the option for those used to R and its command line. I do not think that this kind of user would be interested in animated graphics.

andrechalom commented 9 years ago

Yes, I am also inclined to think that we should keep the animation in the interface. As the shiny interface is written in R (and is copylefted code), we could reuse the code for other interfaces later.

On Fri, Jul 3, 2015 at 12:32 PM, Paulo Inácio Prado < notifications@github.com> wrote:

Still, I think that animation is a feature for the Rsampling-shiny, because I see Rsampling as an engine and aslo the option for those used to R and its command line. I do not think that this kind of user would be interested in animated graphics.

— Reply to this email directly or view it on GitHub https://github.com/lageIBUSP/Rsampling/issues/8#issuecomment-118375211.

adalardo commented 9 years ago

I am not sure! The idea is a tools for teaching, so even if the teacher is a R addicted and use command lines to show permutations, will be nice to have to possibility to show an animated graphics. We may give this option as a argument inside Rsampling function.

2015-07-03 13:27 GMT-03:00 andrechalom notifications@github.com:

Yes, I am also inclined to think that we should keep the animation in the interface. As the shiny interface is written in R (and is copylefted code), we could reuse the code for other interfaces later.

On Fri, Jul 3, 2015 at 12:32 PM, Paulo Inácio Prado < notifications@github.com> wrote:

Still, I think that animation is a feature for the Rsampling-shiny, because I see Rsampling as an engine and aslo the option for those used to R and its command line. I do not think that this kind of user would be interested in animated graphics.

— Reply to this email directly or view it on GitHub <https://github.com/lageIBUSP/Rsampling/issues/8#issuecomment-118375211 .

— Reply to this email directly or view it on GitHub https://github.com/lageIBUSP/Rsampling/issues/8#issuecomment-118387076.

Alexandre Adalardo de Oliveira Professor Doutor Universidade de São Paulo IB-Depto Ecologia http://labtrop.ib.usp.br http://ecologia.ib.usp.br/labtrop adalardo@usp.br


aleadalardo@gmail.com http://scholar.google.com.br/citations?user=O1gcrwIAAAAJ&hl=pt-BR

vrios commented 9 years ago

I think separating the visualizations from the permutation engine is a good idea, it keeps the code encapsulated and introduces less dependencies to the core package, such that a bug in the graphics would not keep the permutation from running. I think I can get the pass by reference to work ( but only after next week :/ ), if so the engine would not have to change at all. Adding the animations like the vegas and simula functions was my first idea also and could be included as basic plots. but the shiny interface seems to me a much more elegant way to do it

andrechalom commented 9 years ago

As we have a very nice animation on the shiny interface (see https://github.com/andrechalom/Rsampling-shiny/releases/tag/v1.3), I don't think this is an issue for the base package.