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

Slow loading (large object) when animation is made using graphjs and lot of layouts #81

Open
rozsasarpi opened this issue Mar 11, 2018 · 3 comments

Comments

@rozsasarpi
Copy link

rozsasarpi commented Mar 11, 2018

Hi Bryan,

First, thanks for this great package.

I'm trying to use it to create a 3D time-evolution plot of a Lorenz system. My approach is to use the graphjs function with numerous layouts representing consecutive time steps (evo_layout). The first layout contains all the points (nodes) collapsed into a single point, the initial position. Then by each step the points (nodes) are moving along the precalculated path, step-by-step changing their coordinates. This approach works; however, to achieve a sufficiently smooth path I need about 1000 discretization points, which create a quite large (~20Mb) layout list variable, which slows down very much the loading of the shiny app.

Do you have any suggestions on how to make the animation more efficient, e.g. by reducing the size of the layout list somehow, or by using a different approach?

Please find the R-files in the attached zip. lorenz_animation.zip
It contains files for a minimal shiny app (ui.R, server.R).
prepare_lorenz.R is to be run before launching the shiny app, it generates the variables needed for the animation. In this file line 8 controls the coarseness of the discretization:
tt = seq(0, 10, by = 0.05) is too coarse,
tt = seq(0, 10, by = 0.01) would be needed.

You can take a look at a low resolution (discretized to 200 points) version of it here:
http://ec2-18-197-104-223.eu-central-1.compute.amazonaws.com:3838/threejs_test2/

Thank you in advance for any suggestions!

Arpi

@bwlewis
Copy link
Owner

bwlewis commented Mar 13, 2018

Thanks! I'm taking a look at this now. Indeed the JSON approach used by htmlwidgets is quite data-heavy. I'll let you know what I come up with...

@bwlewis
Copy link
Owner

bwlewis commented Mar 13, 2018

Here is a hack that can help quite a bit in your case, but it's not an elegant solution...add the option signif = 3 to your graphjs invocation:

   graphjs(g,
            layout = evo_layout,
            vertex.size = '0',
            vertex.color = "white",
            edge.color = "white",
            edge.width = 1,
            bg = 'black',
            use.orbitcontrols=TRUE,
            fpl = n/5/200,
            signif = 3)

in the server.R file. That is enough to preserve most of the fidelity of your plot and really cuts down on the output size.

It's still kind of lame, but it's the best I can do for now. A better approach might be to invent a way to parameterize animations in the new, experimental render() function...but that's in the future for sure.

@rozsasarpi
Copy link
Author

Thanks a lot for the suggestion! However, it does not seem to speed up the process. Maybe I'm not measuring it correctly but the size of the output produced by:

graphjs(g,
            layout = evo_layout,
            vertex.size = '0',
            vertex.color = "white",
            edge.color = "white",
            edge.width = 1,
            bg = 'black',
            use.orbitcontrols=TRUE,
            fpl = n/5/200,
            signif = 3)

with and without the signif argument are virtually the same. I guess one issue is loading the large layout list (evo_layout; lorenz_attr = readRDS('lorenz_attr.rds')). I do not know how to cut its size down.

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

2 participants