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
Progressively render the template using jinja's generate method #133
Progressively render the template using jinja's generate method #133
Conversation
e6745d4
to
29f2f8a
Compare
There is a bit more control now, starting the kernel and executing the notebook are two steps, allowing for even quicker page loading. The flow of data is now:
|
29f2f8a
to
31e2545
Compare
31e2545
to
a5589ed
Compare
a5589ed
to
ff3b3ed
Compare
Would |
Good point, that part needs refactoring, I think it would be good to separate that in a different PR. The 'issue' is that we now have two communication channels (http and websocket) that are async, so you can imagine the html outputting 'render widget with id XYZ', while that widget is not yet constructed via the websocket, and visa versa. In voila-vuetify we had a similar issue (https://github.com/QuantStack/voila-vuetify/blob/7af86f0261f10947da33dc13f4e5a7a750c598c1/share/jupyter/voila/templates/vuetify-base/nbconvert_templates/util.js#L49), and if I'm not mistaken you've worked on a similar issue in the LabManager. |
If the widget data has not arrived yet, the widget renderer can await the model promise. There should be support for this in the widget manager, so I think that is tractable. The main reason I asked is that if we are continuously trying to check for |
Hmm, maybe a better solution is MutationObserver ? I'll need to research that, including how it interacts with progressive rendering. |
|
voila/handler.py
Outdated
all_cells = list(nb.cells) # copy the cells, since we will modify in place | ||
for cell in all_cells: | ||
# we execute one cell at a time | ||
nb.cells = [cell] # reuse the same notebook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean we can't make a single copy of notebook, and use that copy to execute one cell at a time (nb_copy.cells = [cell]
), while keeping the original notebook intact?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could, but as the code is now, there is no need for it. The general strategy in nbconvert is to do copy.deepcopy. But as of now, each requests reads the notebook file and gives a new notebook object.
Do we want the progressive rendering to be part of the default template, or move it to a new template? |
I think it should be a core feature of voila templates, together with the template refactor, I think we can have support for this in all templates with zero (yes free / out of the box) of minimal effort. |
That would be great, so template authors don't need to think about explicitly calling |
Yes, that's indeed the plan. |
share/jupyter/voila/templates/default/nbconvert_templates/voila.tpl
Outdated
Show resolved
Hide resolved
A few glitches with Firefox that we also noticed with @maartenbreddels on Friday:
|
share/jupyter/voila/templates/default/nbconvert_templates/voila.tpl
Outdated
Show resolved
Hide resolved
My experimental branch with asyncio works perfect, I still see that it takes a while for Firefox to start rendering, but it does work. |
Including the rendering of the font awesome icon? |
I guess we could leave this for a follow-up PR (with the async goodness) |
Yes |
…for progressive rendering
2436ad9
to
4fdf385
Compare
🎉 |
Thanks @maartenbreddels! |
If you call Template.generate instead of Template.render, jinja returns snippets (for each statement a snippet, not expressions!).
The key here is that:
Is a statement, so all html before this will be send to the browser (and allows the browser to progressively load, and show a spinner). However, it seems that the nb variable is not updates, the rest of the template seems to use the old 'nb' variable.
Replaces #71