Skip to content

Instantly share code, notes, and snippets.

@teh
Created June 21, 2016 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teh/9600133d17850111026f0c0a51c6fa40 to your computer and use it in GitHub Desktop.
Save teh/9600133d17850111026f0c0a51c6fa40 to your computer and use it in GitHub Desktop.
{%- extends 'full.tpl' -%}
{%- block input_group -%}
{%- endblock input_group -%}
# http://nbconvert.readthedocs.io/en/latest/execute_api.html
# http://nbconvert.readthedocs.io/en/latest/nbconvert_library.html
import flask
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor, Preprocessor
from nbconvert import HTMLExporter
from traitlets.config import Config
ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
c = Config()
c.Exporter.template_file = 'cell'
c.HTMLExporter.preprocessors = [ep]
app = flask.Flask(__name__)
@app.route('/')
def render():
notebook_filename = '/tmp/testnotebook.ipynb'
with open(notebook_filename) as f:
nb = nbformat.read(f, as_version=4)
html_exporter = HTMLExporter(config=c)
html_exporter.preprocessors
body, resources = html_exporter.from_notebook_node(nb)
return body
if __name__ == '__main__':
app.run(port=8082, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment