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

Fake requirejs & JS transform specific to electron frontends #1714

Closed
wants to merge 4 commits into from

Conversation

rgbkrk
Copy link
Member

@rgbkrk rgbkrk commented May 24, 2017

This is the beginning of custom transforms for electron based frontends to handle "Jupyter-style" JS and HTML in a secure and friendly way. Secure because we could lock it down. Friendly because we'll try to match some invariants:

  • Access to a partially limited requirejs as require -- will likely use the vm module for js runtime
    • We'll provide some faked access to more common require paths, including vega and others since we already support vega
  • All the output from a single execution request (cell) should get rendered in the same webview

There's no code here yet, figured I should post where I'm headed with it.

After this PR I'm going to make a version that is web specific that will use the requirejs helper code.

Libraries to support

  • nbextensions/jupyter-vega/index
  • d3

Libraries definitely not going to be supported as part of this:

  • ipywidgets
  • pythreejs (relies on widgets)
  • the jupyter and ipython js APIs from the classic notebook
  • plotly - we already handle the plotly mimetype, we won't support the text/html version from them
  • holoviews
  • bokeh

Related PR: #1709

@codecov-io
Copy link

codecov-io commented May 24, 2017

Codecov Report

Merging #1714 into master will increase coverage by 1.1%.
The diff coverage is 100%.

@@            Coverage Diff            @@
##           master    #1714     +/-   ##
=========================================
+ Coverage   79.04%   80.15%   +1.1%     
=========================================
  Files          62       60      -2     
  Lines        2047     1990     -57     
=========================================
- Hits         1618     1595     -23     
+ Misses        429      395     -34

@rgbkrk
Copy link
Member Author

rgbkrk commented May 24, 2017

It works!

screen shot 2017-05-24 at 4 06 23 pm

Time to push the code.

@rgbkrk rgbkrk requested a review from lgeiger May 25, 2017 00:01
@rgbkrk
Copy link
Member Author

rgbkrk commented May 25, 2017

Ready for feedback @lgeiger, primarily for the sake of Hydrogen. I started with "just make it work" and haven't adapted the webview stuff yet. Outline a plan and I'll tackle it. 😄 I'm still iterating a bit with the requirejs setup, as I want to use something similar in #1709 for the web based frontends too.

@rgbkrk rgbkrk force-pushed the electron-transforms branch 2 times, most recently from b0affc3 to 2756395 Compare May 25, 2017 01:04
expect(component.shouldComponentUpdate({ data: "<b>woo</b>" })).toBeFalsy();
expect(
component.shouldComponentUpdate({ data: "<b>womp</b>" })
).toBeTruthy();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realize that Stephen Colbert wrote enzyme.

@rgbkrk
Copy link
Member Author

rgbkrk commented May 26, 2017

Full query across all public notebooks for use of requirejs calls: https://bigquery.cloud.google.com/savedquery/300830567303:6116513b17ca4a77b58fec869fe5a846

😄

@rgbkrk
Copy link
Member Author

rgbkrk commented May 26, 2017

As a result of doing these queries, the modules that we should support include:

Possible contenders:

  • topojson
  • escher
  • cartogram
  • krisk
  • slick_grid
  • data_grid
  • echarts
  • c3
  • brunel

Other large uses, haven't diagnosed much about them:

  • //dato.com/files/canvas/1.6.1/js/ipython_app.js

@rgbkrk
Copy link
Member Author

rgbkrk commented May 26, 2017

Here are all the modules in public repos. These are uniqued yet not counted very well...:

  268 - //dato.com/files/canvas/1.6.1/js/ipython_app.js
  174 - //dato.com/files/canvas/1.5.2/js/ipython_app.js
  153 - plotly
  145 - nbextensions/jupyter-vega/index
   89 - d3
   81 - https://static.turi.com/products/graphlab-create/2.1/canvas/js/ipython_app.js
   69 - downloadable
   58 - base/js/utils
   49 - //dato.com/files/canvas/1.8.5/js/ipython_app.js
   38 - echarts
   37 - vintage
   37 - shine
   37 - roma
   37 - macarons
   37 - infographic
   37 - dark
   36 - //dato.com/files/canvas/1.7.1/js/ipython_app.js
   35 - style!/static/extensions/charting.css
   35 - extensions/charting
   33 - JSRootCore
   33 - //dato.com/files/canvas/1.8.4/js/ipython_app.js
   31 - imolecule
   29 - matta
   26 - cytoscape
   22 - https://static.turi.com/products/graphlab-create/2.0/canvas/js/ipython_app.js
   22 - //dato.com/files/canvas/1.6/js/ipython_app.js
   16 - //dato.com/files/canvas/1.9/js/ipython_app.js
   15 - escher
   13 - notebook
   11 - style!/static/extensions/bigquery.css
   11 - https://root.cern.ch/js/3.4/scripts/d3.v3.min.js
   11 - https://root.cern.ch/js/3.4/scripts/JSRootPainter.min.js
   11 - https://root.cern.ch/js/3.4/scripts/JSRootCore.min.js
   11 - extensions/bigquery
   11 - //turi.com/files/canvas/1.8.5/js/ipython_app.js
   10 - music21
   10 - codemirror/mode/clike/clike
   10 - //turi.com/files/canvas/1.6.911/js/ipython_app.js
    9 - //dato.com/files/canvas/1.8.3/js/ipython_app.js
    8 - igraph
    7 - ipnm
    7 - https://static.turi.com/products/graphlab-create/1.10/canvas/js/ipython_app.js
    6 - topojson
    6 - jgraph
    6 - //dato.com/files/canvas/1.10.1/js/ipython_app.js
    5 - widgets/js/widget
    5 - slick_grid
    5 - https://static.turi.com/products/graphlab-create/2.0.1/canvas/js/ipython_app.js
    5 - data_grid
    5 - base/js/dialog
    4 - widgets/js/manager
    4 - cloud
    4 - cartodblib
    4 - //turi.com/files/canvas/1.6.1/js/ipython_app.js
    3 - candela
    3 - c3
    3 - BrunelEventHandlers
    3 - BrunelData
    3 - BrunelD3
    3 - //turi.com/files/canvas/1.6.916/js/ipython_app.js
    3 - //dato.com/files/canvas/1.8.2/js/ipython_app.js
    2 - vis
    2 - three
    2 - sankey
    2 - pivot
    2 - parsets
    2 - mapboxgl
    2 - js/stacked.js
    2 - jquery
    2 - https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js
    2 - http://fperucic.github.io/treant-js/vendor/raphael.js
    2 - dc
    2 - crossfilter
    2 - cola
    2 - cartogram
    2 - bootstrap
    2 - base/js/namespace
    2 - JSRootPainter
    2 - //turi.com/files/canvas/1.6/js/ipython_app.js
    2 - //dato.com/files/canvas/1.6.908/js/ipython_app.js

Decent survey though. Note that I filtered out any occurences that were less than 2.

@rgbkrk
Copy link
Member Author

rgbkrk commented May 26, 2017

Note that dato / graphlab / turi come up often in the results as well, as part of a coursera course. I can't tell if they're well supported any more -- I'd like to use a canonical version as much as possible.

@rgbkrk
Copy link
Member Author

rgbkrk commented May 26, 2017

Ok now that I've had a go at this for a bit, it's definitely seeming like we'd need to approach parts of this differently:

Long term plan

JS output and HTML output should have the same output context / area. This likely means doing a unified iframed (webview for electron) display area. We'd still inject dependencies (vega, plotly, etc.)

Short term plan

Provide document and window to the "sandbox" so we don't break current functionality. The only thing that's changing here is that we're providing a requirejs "shim" of sorts and for Atom, we'll be using vm. We'll also be able to provide better error messages for use of objects we don't have (e.g. IPython, Jupyter).

@rgbkrk rgbkrk changed the title [WIP] HTML and JS transforms specific to electron frontends Fake requirejs & JS transform specific to electron frontends May 26, 2017
* Support the specific require path for both of these
* Includes vega-embed and d3 in deps
@rgbkrk
Copy link
Member Author

rgbkrk commented May 26, 2017

Once this passes, it's ready to go and provides us a nice path for supporting vega/altair, d3, and informing users in a much richer way about what we can and can't support.

@rgbkrk rgbkrk mentioned this pull request May 26, 2017
3 tasks
@lgeiger
Copy link
Member

lgeiger commented May 28, 2017

Just tried out this branch 🎉

I'm hitting a strange bug when trying a simple bokeh example:

from bokeh.io import push_notebook, show, output_notebook
from bokeh.layouts import row, gridplot
from bokeh.plotting import figure, show, output_file
output_notebook()

import numpy as np

x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)
TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select"

p1 = figure(title="Legend Example", tools=TOOLS)
p1.circle(x,   y, legend="sin(x)")
p1.circle(x, 2*y, legend="2*sin(x)", color="orange")
p1.circle(x, 3*y, legend="3*sin(x)", color="green")
show(p1)

This used to work in previous versions of nteract, but now the app completely crashes without any debug output.

@rgbkrk
Copy link
Member Author

rgbkrk commented May 29, 2017

Whoa! Ok I'll check that out.

@rgbkrk
Copy link
Member Author

rgbkrk commented Aug 10, 2017

I'm beginning to think that HTML output should end up in an iframe that we provide certain libraries into, while also handling the resize. I'm going to try out a little mockup.

@rgbkrk
Copy link
Member Author

rgbkrk commented Aug 15, 2017

Will come back to this again later. Cleaning up PRs for now.

@rgbkrk rgbkrk closed this Aug 15, 2017
@rgbkrk rgbkrk deleted the electron-transforms branch August 15, 2017 22:47
@lock
Copy link

lock bot commented Apr 2, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked and limited conversation to collaborators Apr 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants