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

does voila allow to get message from frontend? #346

Closed
hainm opened this issue Aug 9, 2019 · 17 comments
Closed

does voila allow to get message from frontend? #346

hainm opened this issue Aug 9, 2019 · 17 comments

Comments

@hainm
Copy link

hainm commented Aug 9, 2019

hi all,

I've been developing a feature in nglview for movie making of the trajectory snapshots.
Basically the backend will send 3D coordinates to frontend for rendering, the frontend will send back the image data (base64) to backend; once the backend got the image data, it will again send the next coordinates for next rendering.

I want to use voila to run the notebook app until it finished to get the movie output. However, it seems that voila does not allow the message from frontend. Is this correct? If yes, can voila have an option to allow that (which is similar to --enable_nbextensions=True).

thanks
PS: The nglview feature is here and related code is here

@jtpio
Copy link
Member

jtpio commented Aug 12, 2019

Right, voila doesn't allow arbitrary code execution (execute requests). Only the following message types:

https://github.com/QuantStack/voila/blob/21db1c318eb222f391fceb0ed4e6fc8670e0b6b3/voila/app.py#L378-L383

However this doesn't seem to be the case in this example (at first glance).
Maybe you have an example notebook / Binder we could use to see what is happening in voila?

@hainm
Copy link
Author

hainm commented Aug 12, 2019

hi @jtpio,
Can you please try this: https://mybinder.org/v2/gh/hainm/nglview/voila?filepath=notebooks%2Fmovie_making.ipynb

I don't know how to run voila there but everything you need is already included.

@jtpio
Copy link
Member

jtpio commented Aug 12, 2019

@hainm thanks for sharing this, will have a look.

To run voila on Binder you can use the server extension endpoint: https://mybinder.org/v2/gh/hainm/nglview/voila?urlpath=voila/render/notebooks%2Fmovie_making.ipynb

@hainm
Copy link
Author

hainm commented Aug 12, 2019

thanks @jtpio.

One possible explanation is that voila is trying to execute code from all the notebook cells before displaying the view. In my case, the view must be displayed before calling the movie maker.

@hainm
Copy link
Author

hainm commented Aug 12, 2019

Probably related to this issue: #142

@hainm
Copy link
Author

hainm commented Aug 12, 2019

oops, likely not. I change the code a bit to only execute the movie making if a button is clicked, but that does not help.

from IPython.display import *
from ipywidgets import *
import nglview as nv
from nglview.contrib.movie import MovieMaker
import pytraj as pt

traj = pt.load(nv.datafiles.XTC, nv.datafiles.PDB)[:5]
view = nv.show_pytraj(traj, default=False)
view.center()
view.add_surface('protein', opacity=0.5, color='residueindex')
view.control.orient([15.69986420582941,
 114.8276262266868,
 48.816742057652796,
 0,
 -18.22863682402078,
 -46.5629522451937,
 115.38869989652724,
 0,
 123.43490126182644,
 -21.481422658119275,
 10.831316500165215,
 0,
 -39.1268284890941,
 -46.69809684423501,
 -44.63013982367478,
 1])



movie = MovieMaker(view, in_memory=True, output='abc.gif')

def make(b):
    movie.make()
    
button = Button(description='click me')
button.on_click(make)

view
display(button), display(movie._progress)

@jtpio
Copy link
Member

jtpio commented Aug 13, 2019

Probably related to this issue: #142

Yes. Also the notebook will display an error after running it with Restart and run all, since the animation is being asynchronously generated and not ready yet.

@hainm
Copy link
Author

hainm commented Aug 13, 2019 via email

@jtpio
Copy link
Member

jtpio commented Aug 14, 2019

That should work.

Are you running voila in standalone mode with the enable_nbextensions flag enabled?

voila --enable_nbextensions=True

@hainm
Copy link
Author

hainm commented Aug 14, 2019

Yes, standalone mode (by running voila in terminal).

I don’t recall I used enable_nbextensions=True but how does this help? I can see the rendering but the movie animation does not work.

@maartenbreddels
Copy link
Member

the last example you pasted works fine here.

@hainm
Copy link
Author

hainm commented Aug 21, 2019

hi @maartenbreddels, that does not work in my computer with voila 0.1.9.

Here is the screenshot after 1 minute after I clicked the button. The expectation is the progress bar should be updated.

voila

@hainm
Copy link
Author

hainm commented Aug 21, 2019

here is correct behavior in the notebook ,where the progress bar is updated.
voila1

@jtpio
Copy link
Member

jtpio commented Oct 2, 2019

@hainm any updates on this or still the same issue?

@hainm
Copy link
Author

hainm commented Oct 2, 2019

Do you mean I should try the latest voila and report here? The issue happened with voila 0.1.9.

@jtpio
Copy link
Member

jtpio commented Oct 2, 2019

Yes just to know if this was still an issue.

@hainm
Copy link
Author

hainm commented Oct 2, 2019

thanks @jtpio, this example works like a champ with voila 0.1.12.

@hainm hainm closed this as completed Oct 2, 2019
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

3 participants