Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display in RStudio Viewer #1

Closed
ramnathv opened this issue Feb 2, 2016 · 11 comments
Closed

Display in RStudio Viewer #1

ramnathv opened this issue Feb 2, 2016 · 11 comments

Comments

@ramnathv
Copy link

ramnathv commented Feb 2, 2016

First off, really cool work with this package. I wish this had been around when I was teaching statistics 😄 . A few ideas to enhance the utility of this package.

Display in RStudio

It would be nice if gganimate output could be displayed in RStudio viewer. Here is some quick and dirty code to do it.

p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
  geom_point() +
  scale_x_log10()

tf <- tempfile(fileext = '.gif')
gg_animate(p, tf, autobrowse = FALSE)
d <- htmltools::tags$img(src = base64encode::dataURI(file = "output.gif", mime="image/gif"))
htmltools::browsable(d)

Animation with Controls

This is possible with scianimator, but I find it really clunky, and the jquery requirement makes it meaty. If gganimate can return an array of image paths, it should not be hard to write a htmlwidget that would display it with controls. I can prototype something for you if this is of interest.

@timelyportfolio
Copy link

👍

@dgrtwo
Copy link
Collaborator

dgrtwo commented Feb 2, 2016

Oh excellent! I had been wondering how to present animations in RStudio but hadn't yet found browsable in htmltools!

The one thing stopping this implementation is that as per #3 there are some issues with saving plots to a non-local directory in animation. I'm working on fixing them.

A controllable in-RStudio animation widget would be really great and I'd be extremely interested in it! I'll probably be changing the output of gg_animate to be something like a "gganimate" object, which contains the relevant list of image links and whose print method would display the above browsable. So if you had a prototype htmlwidget that took a list of image files it would be easy to add it.

@ramnathv
Copy link
Author

ramnathv commented Feb 2, 2016

That makes sense. I will prototype a more generic widget that will display a sequence of images as an animation. This would make it usable beyond gganimate. I will update you once I have a working prototype.

@ramnathv
Copy link
Author

ramnathv commented Feb 4, 2016

Here is an initial prototype http://jsfiddle.net/ramnathv/cabkohuk/. It is a fairly straightforward one to make into a widget. I have mainly tried to replicate features from scianimator which is terrific, but heavy due to its jquery dependency. My rewrite uses mithril which is a lightweight MVC framework that clocks at 8kb gzipped and hence really lightweight.

If there are additional features you would like to see in an animation viewer, feel free to add them so I can incorporate them.

@timelyportfolio
Copy link

Very nice, will it work with svg either directly or possibly using rsvg?

@timelyportfolio
Copy link

also, just noticed the keybinding. Love it.

@timelyportfolio
Copy link

@ramnathv I remembered this project https://github.com/socib/Leaflet.TimeDimension and thought it might help regarding functionality, look, and code.

dgrtwo pushed a commit that referenced this issue Feb 8, 2016
…the simple examples in the README and elsewhere.

* The gg_animate function now doesn't display or save files directly, but through the `gg_animate_save` function (which it does call if it is given a filename). It now returns a `gg_animate` object then holds on to the location and content of those saved files.
* The `print` method of `gg_animate` objects now allows browsing of GIFs within RStudio, as described in issue #1. When knitr is in progress it still prints all figures in a sequence, leaving knitr to handle the animation. We'll leave #1 open while we work on other widgets allowing in-RStudio exploration
* Fixed #3 by using withr to execute the saving function in the specified subdirectory.
* Fixed #4 with a special case for factors, which should be combined using `unlist`, as opposed to other types of frame columns (such as Date vectors) that should be combined using `do.call(c` (see #2)
* Added some basic tests that require ffmpeg and ImageMagick to complete.
@dgrtwo
Copy link
Collaborator

dgrtwo commented Feb 8, 2016

@ramnathv I've integrated the gg_animate object with a print method plan, so it's now browsable in RStudio. Please try it!

That prototype is great! Two thoughts:

  • I'd like the option to give frames titles instead of numbers: that is, instead of 0-12 on the top row, it should be possible to have 1715 UTC through 2030 UTC. The gapminder example, for instance, could have the years 1952 through 2007 in the little blue boxes. This would not work in all cases (e.g. when there are many frames or their titles are long) so it should definitely be optional, but it would especially ease browsing when the title is a factor rather than continuous.
  • There should ideally be a button to turn on looping, or at least clicking play when the animation is done should start over

I'd definitely be interested in seeing this turned into a widget and I'd get it into gg_animate right away.

@ramnathv
Copy link
Author

ramnathv commented Feb 8, 2016

@dgrtwo The print method works great!

Thanks for your feedback on the animator widget. Your suggestions can be easily incorporated. I will put them on my list of stuff to implement. I will update the prototype and ping you.

@happyshows
Copy link

just curious about the status, is a shiny friendly version available now?

@mwm-cbus
Copy link

First off, really cool work with this package. I wish this had been around when I was teaching statistics 😄 . A few ideas to enhance the utility of this package.

Display in RStudio

It would be nice if gganimate output could be displayed in RStudio viewer. Here is some quick and dirty code to do it.

p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
  geom_point() +
  scale_x_log10()

tf <- tempfile(fileext = '.gif')
gg_animate(p, tf, autobrowse = FALSE)
d <- htmltools::tags$img(src = base64encode::dataURI(file = "output.gif", mime="image/gif"))
htmltools::browsable(d)

Animation with Controls

This is possible with scianimator, but I find it really clunky, and the jquery requirement makes it meaty. If gganimate can return an array of image paths, it should not be hard to write a htmlwidget that would display it with controls. I can prototype something for you if this is of interest.

Love this :)
Would vote to have this rather than opening separately in default program for images, or to have the option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants