Permalink
Browse files

Merge pull request #738 from twosigma/master

Upgrade ipywidgets to v7, with a fallback for v6
  • Loading branch information...
jasongrout committed Nov 17, 2017
2 parents ffda79b + a9210a7 commit 67ee47e55fa697614e03aa060a86019f75f2ddca
Showing with 34 additions and 2 deletions.
  1. +2 −0 nbviewer/app.py
  2. +5 −0 nbviewer/providers/base.py
  3. +1 −2 nbviewer/templates/layout.html
  4. +26 −0 nbviewer/templates/notebook.html
View
@@ -252,6 +252,7 @@ def make_app():
hub_api_token=os.getenv('JUPYTERHUB_API_TOKEN'),
hub_api_url=os.getenv('JUPYTERHUB_API_URL'),
hub_base_url=os.getenv('JUPYTERHUB_BASE_URL'),
ipywidgets_base_url=options.ipywidgets_base_url,
)
if options.localfiles:
@@ -305,6 +306,7 @@ def init_options():
define("statsd_port", default=8125, help="Port on which statsd is listening for metrics on statsd_host", type=int)
define("statsd_prefix", default='nbviewer', help="Prefix to use for naming metrics sent to statsd", type=str)
define("base_url", default='/', help='URL base for the server')
define("ipywidgets_base_url", default="https://unpkg.com/", help="URL base for ipywidgets package", type=str)
def main(argv=None):
@@ -189,6 +189,10 @@ def frontpage_setup(self):
def mathjax_url(self):
return self.settings['mathjax_url']
@property
def ipywidgets_base_url(self):
return self.settings['ipywidgets_base_url']
@property
def statsd(self):
if hasattr(self, '_statsd'):
@@ -251,6 +255,7 @@ def template_namespace(self):
"static_url": self.static_url,
"from_base": self.from_base,
"google_analytics_id": self.settings.get('google_analytics_id'),
"ipywidgets_base_url": self.ipywidgets_base_url,
}
def breadcrumbs(self, path, base_url):
@@ -77,7 +77,6 @@
<script src="{{ static_url("components/jquery/dist/jquery.min.js") }}"></script>
<script src="{{ static_url("components/requirejs/require.js") }}"></script>
<script src="{{ static_url("components/moment/min/moment.min.js") }}"></script>
<!-- Navbar
================================================== -->
<nav id="menubar" class="navbar navbar-default navbar-fixed-top" data-spy="affix">
@@ -157,7 +156,6 @@
</footer>
{% endblock footer %}
<script src="https://unpkg.com/jupyter-js-widgets@2.0.*/dist/embed.js"></script>
<script src="{{ static_url("components/bootstrap/js/bootstrap.min.js") }}"></script>
<script src="{{ static_url("components/headroom.js/dist/headroom.min.js") }}"></script>
<script src="{{ static_url("components/headroom.js/dist/jQuery.headroom.min.js") }}"></script>
@@ -190,6 +188,7 @@
});
});
</script>
<!--NEW RELIC Stop Perf Measurement-->
{{ nrfoot()| safe }}
<!--NEW RELIC End-->
@@ -80,6 +80,32 @@
init_mathjax();
</script>
{% endblock mathjax %}
{% block ipywidgets %}
<script>
(function() {
function addWidgetsRenderer() {
var mimeElement = document.querySelector('script[type="application/vnd.jupyter.widget-view+json"]');
var scriptElement = document.createElement('script');
var widgetRendererSrc = '{{ ipywidgets_base_url }}@jupyter-widgets/html-manager@*/dist/embed-amd.js';
var widgetState;
try {
widgetState = mimeElement && JSON.parse(mimeElement.innerHTML);
if (widgetState && (widgetState.version_major < 2 || !widgetState.version_major)) {
widgetRendererSrc = '{{ ipywidgets_base_url }}jupyter-js-widgets@*/dist/embed.js';
}
} catch(e) {}
scriptElement.src = widgetRendererSrc;
document.body.appendChild(scriptElement);
}
document.addEventListener('DOMContentLoaded', addWidgetsRenderer);
}());
</script>
{% endblock ipywidgets %}
{% endblock extra_head %}

0 comments on commit 67ee47e

Please sign in to comment.