-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Shinystan animated #126
base: develop
Are you sure you want to change the base?
Shinystan animated #126
Conversation
…n explore page, but instead use a single select option for the y axis and multiple select for the x axis. This allows the animation of multiple variables together compared to a single third (y) variable.
… graphs working now in the explore tab
…x instead of the one in the tab animate itself
…loser to the underlying .animate_plot function
…ecause renderImage requires a file reference. Instead, before the user clicks the Animate button, a blank .png image is returned to renderImage. Sort of a hack, but it works.
…e not imported, they only need to be installed
This is really cool. Thanks! I played around with something like this for I've only taken a quick glance at it so far but I'll review the whole thing Thanks again! On Tuesday, June 14, 2016, saudiwin [email protected] wrote:
|
Sure thing take your time. I tried to test it thoroughly, but it is definitely experimental. A particular question is what the default settings should be as producing video is resource-intensive. |
…tios instead of just raw pixel size. good for viewing the videos on a variety of media
Haven't gone through the code yet but I do have some general
|
That is certainly an idea re: using a separate function. Were you thinking of just having command line usage or creating a separate shiny interface? I think in an ideal world someone could be running a video production task in the background while continuing to look at other parts of the shiny app. I'm not sure though how to do that in shiny code. I also think that it might be good to disable the video production in any app that is shared online because it would take up a lot of resources on the server, and I know those are usually limited. When I was testing settings, I would only run it relatively low smoothing, and that doesn't take too long. But because interpolation is multiplicative, it massively increases the number of plots. So I think part of the resource intensity issue may depend on getting the right settings that users would find useful. If someone wanted to have a full-length, high-quality video, then they could take a full hour to produce it, but if someone just wanted to examine a particular difficult sampling problem, they could use much less "pretty" settings. The function is essentially 1) interpolate the data, 2) melt the data either by X variables or by chain, 3) run ggplot on the melted data, and 4) create the animation. So because #3 is separate, it is easy to switch out settings or change the type of plot used. By animated histogram, are you thinking of running it on full log-posterior samples, indexed by both n and t? I see no reason why that shouldn't be possible. Of course, you could get seasick watching it... |
…into separate_tab
Hi Robert, a bunch of comments inline below: On Wednesday, June 15, 2016, Robert Kubinec [email protected]
I also think that it might be good to disable the video production in any
And there are probably all sorts of other interesting things to look at Jonah |
Yeah that's interesting. Adding histograms should be pretty easy given how modular ggplot2 is. One of the cool things about animation is that it seems like more variables can be combined in one plot because you can see change in variation over time, while one-dimensional plots can become messy quickly (like the pairs plot). I'll go ahead and add histogram support. An R-level function call with parallel support makes a lot of sense. I think that I could make a wrapper for the animation function that splits up the frames into separate objects and then recombines them before processing into video. That could be put into an mclapply loop for large videos. I think to make it an R function call I would need to add in some convenience functions to pull apart the shinystan object, but nothing too difficult. Most of the difficult coding involved getting from ggplot to video; everything else is just data processing. |
Ok cool. Let me know if you have any questions about accessing anything On Thursday, June 16, 2016, Robert Kubinec [email protected] wrote:
|
Sounds good, Jonah. It's been a fun project to work on. |
OK I've got basic histogram support working: It only works by manually selecting each variable of the density individually and it only can show one chain at a time because I set up the original function to show scatterplots. To enable multiple chains I have to change the way that the data is melted; I think what I need to do is create a sub-function that does data processing, currently the code is getting a little busy. |
…ation functions for saving and exporting video
I am submitting a pull request that creates a new Animation tab within the Explore page. I had this idea for a while that it would be useful to animate the time dimension instead of looking at chains in a "flat" dimension like a line graph. I've also benefited a lot from shinystan, so I wanted to give a bit back. My code makes use of the gg_animate package to create a .WEBM movie from scatterplots of one or more X variables and a single Y variable. The gg_animate package will produce one frame for each iteration in the Markov chain. Furthermore, I used the tweenr package to add interpolation between the Markov transitions; this enables the animation to run very smoothly.
The package also requires use of the ffmpeg library. I included a markdown file that loads in the animation tab explaining what the user must do in order to create movies.
Currently I have tested the animation using sample data from the rstan package; the test file is in the tests folder. It seems to work with a range of options, including many of the options from the bivariate scatterplot (on which I largely based the code). I have tried to keep my code separate as much as possible from other shinystan functions, and also to use current code format and method.
The resulting videos are fairly high quality (default setting 2000x1000 pixels). However, production of the plots is slow as ggplot has to create a separate graph for each animation. But once the files are produced, they can be downloaded for later storage.
The animation options allow the user to select varying levels of quality in terms of picture size, and also to control animation speed and smoothness. Generally, a more smooth animation results in more frames produced and more time required.
For example, to produce a smooth animation for 200 iterations with 10 smoothing frames, ggplot2 must produce 2,000 separate images, and requires about half an hour of CPU time. This processing could be done in parallel, but would require some work on the gganimate package.
On the plus side, .WEBM files can be uploaded directly to youtube, as I just did with this example. On the downside, it may not display in Safari or Internet Explorer without the user downloading additional plugins.