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

Progressively render the template using jinja's generate method #133

Open
wants to merge 4 commits into
base: master
from

Conversation

Projects
None yet
1 participant
@maartenbreddels
Copy link
Member

commented May 13, 2019

If you call Template.generate instead of Template.render, jinja returns snippets (for each statement a snippet, not expressions!).
The key here is that:

{%- set nb = notebook_execute() -%}

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

@maartenbreddels maartenbreddels force-pushed the maartenbreddels:progressive_loading branch 3 times, most recently from e6745d4 to 29f2f8a May 17, 2019

@maartenbreddels

This comment has been minimized.

Copy link
Member Author

commented May 17, 2019

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:

  • everything from the start of the template until the next jinja expression is send to the client (can include a spinner, resources etc)
  • The kernel is started, and also this snippet is send to the client (we could for instance start making the websocket connection in the future).
{%- with kernel_id = kernel_start() -%}
  <script id="jupyter-config-data" type="application/json">
  {
      "baseUrl": "{{resources.base_url}}",
      "kernelId": "{{kernel_id}}"
  }
  </script>
.....
{% endwith %}

  • The cells are executed, and once they are done the rest of the template is send to the client.
  {# from this point on, nb.cells contains output of the executed cells #}
  {% do notebook_execute(nb, kernel_id) %}
    <div tabindex="-1" id="notebook" class="border-box-sizing">
      <div class="container" id="notebook-container">
        {{ super() }}
      </div>
    </div>

@maartenbreddels maartenbreddels changed the title WIP: Progressively render the template using jinja's generate method Progressively render the template using jinja's generate method May 17, 2019

@maartenbreddels maartenbreddels force-pushed the maartenbreddels:progressive_loading branch from 29f2f8a to 31e2545 May 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.