Coder Social home page Coder Social logo

jupyter-attic / declarativewidgets Goto Github PK

View Code? Open in Web Editor NEW
120.0 25.0 38.0 10.99 MB

[RETIRED] Jupyter Declarative Widget Extension

Home Page: http://jupyter.org/declarativewidgets/docs.html

License: Other

Makefile 1.53% HTML 39.19% Python 6.62% JavaScript 2.41% Scala 11.69% CSS 0.46% Jupyter Notebook 34.55% R 3.55%
jupyter

declarativewidgets's Introduction

Build Status

Jupyter Declarative Widget Extension

Extension for Jupyter / IPython Notebook to build interactive areas using declarative widgets.

What It Gives You

Watch from minute 21 to 41 of the September 1st Jupyter meeting video recording.

  • A base extension that enable the use of Web Components and Polymer elements
  • A set of core elements facilitate interacting with code running on the kernel
  • Ability of read and query DataFrames from a variety of implementations (i.e. Spark, R, Pandas).
  • Extensions to data binding support and installing of 3rd party elements.
  • Implementations for Python, R (using IRkernel) and Scala (using Apache Toree)

What It Lacks

  • Support for disconnected (no kernel) environments (i.e. nbviewer)

Runtime Requirements

  • Jupyter Notebook 4.0.x, 4.1.x, or 4.2.x running on Python 3.x or Python 2.7.x (see the 0.1.x branch for IPython Notebook 3.2.x compatibility)
  • IPywidgets 4.1.x and 5.1.1+ (R and Scala support not available for 5.0.0 nor 5.1.0)
  • Bower, git - Necessary for installing 3rd party elements straight out of notebook
Optional Requirements based on language support
  • Apache Toree for access to Spark using Scala
  • IRkernel for R language
Additional requirements for Pandas DataFrame queries
  • pip install numexpr
Additional requirements for Python 2.7
  • pip install futures==3.0.3

Try It

We're running a tmpnb instance at http://jupyter.cloudet.xyz with a snapshot of this project (and other related projects) pre-installed.

Install It

In Jupyter 4.2.x
# install the python package
pip install jupyter_declarativewidgets

# Install all parts of the extension to the active conda / venv / python env
# and enable all parts of it in the jupyter profile in that environment
# See jupyter declarativewidgets quick-setup --help for other options (e.g., --user)
jupyter declarativewidgets quick-setup --sys-prefix
# The above command is equivalent to this sequence of commands:
# jupyter serverextension enable --py declarativewidgets --sys-prefix
# jupyter nbextension install --py declarativewidgets --sys-prefix
# jupyter nbextension enable --py declarativewidgets --sys-prefix
In Jupyter 4.0.x and 4.1.x
# install the python package
pip install jupyter_declarativewidgets

# register the notebook frontend extensions into ~/.local/jupyter
# see jupyter cms install --help for other options
jupyter declarativewidgets install --user --symlink --overwrite
# enable the JS and server extensions in your ~/.jupyter
jupyter declarativewidgets activate
Optional install of R support (all Jupyter versions)
# installing R support
jupyter declarativewidgets installr --library path/to/r/libs
# alternatively directly from GitHub
devtools::install_github('jupyter/declarativewidgets', subdir = 'kernel-r/declarativewidgets')
Note

On all Jupyter versions, you will need to restart your notebook server if it was running during the enable/activate step. Also, note that you can run jupyter --paths to get a sense of where the extension files will be installed.

Uninstall It

In Jupyter 4.2.x
# Remove all parts of the extension from the active conda / venv / python env
# See jupyter declarativewidgets quick-remove --help for other options (e.g., --user)
jupyter declarativewidgets quick-remove --sys-prefix
# The above command is equivalent to this sequence of commands:
# jupyter bundler disable --py declarativewidgets --sys-prefix
# jupyter nbextension disable --py declarativewidgets --sys-prefix
# jupyter nbextension uninstall --py declarativewidgets --sys-prefix
# jupyter serverextension disable --py declarativewidgets --sys-prefix

# Remove the python package
pip uninstall jupyter_declarativewidgets
In Jupyter 4.0.x and 4.1.x
# Disable extensions, but no way to remove frontend assets in this version
jupyter declarativewidgets deactivate

# Remove the python package
pip uninstall jupyter_declarativewidgets

Documentation

The latest documentation can be found here.

Documentation is also available from within the notebook. To see the documentation add a cell with

%%HTML
<urth-help/>

Develop

This repository is setup for a Dockerized development environment. On a Mac, do this one-time setup if you don't have a local Docker environment yet.

brew update

# make sure we have node and npm for frontend preprocessing
brew install npm node

# make sure you're on Docker >= 1.7
brew install docker-machine docker
docker-machine create -d virtualbox dev
eval "$(docker-machine env dev)"

Clone this repository in a local directory that docker can volume mount:

# make a directory under ~ to put source
mkdir -p ~/projects
cd !$

# clone this repo
git clone https://github.com/jupyter/declarativewidgets.git

Run the notebook server in a docker container:

cd declarativewidgets

# one time only setup needed to create docker image
make init

# run notebook server in container
make dev

The final make command starts a local Docker container with the critical pieces of the source tree mounted where they need to be to get picked up by the notebook server in the container. Most code changes on your Mac will have immediate effect within the container.

To see the Jupyter instance with extensions working:

  1. Run docker-machine ls and note the IP of the dev machine.
  2. Visit http://THAT_IP:8888 in your browser
Develop Against Python 2.7

You can run a development environment against python 2.7 by adding an environment variable to your make calls.

# Run a development environment against 2.7
PYTHON=python2 make dev

Build & Package

Run make sdist to create a pip installable archive file in the dist directory. To test the package, run 'make server'. This command will run a docker container and pip install the package. It is useful to validate the packaging and installation. You should be able to install that tarball using pip anywhere you please with one caveat: the setup.py assumes you are installing to profile_default. There's no easy way to determine that you want to install against a different user at pip install time.

Test

On a Mac, make test will execute the browser, python and scala tests.

$ make test
Installing and starting Selenium server for local browsers
Selenium server running on port 50625
Web server running on port 2000 and serving from /Users/youruser/declarativewidgets
chrome 45                Beginning tests via http://localhost:2000/generated-index.html?cli_browser_id=0
chrome 45                Tests passed
Test run ended with great success

chrome 45 (102/0/0)

Running python tests...
............................
----------------------------------------------------------------------
Ran 28 tests in 0.006s

Running scala tests...
...
[info] Run completed in 8 seconds, 137 milliseconds.
[info] Total number of tests run: 78
[info] Suites: completed 7, aborted 0
[info] Tests: succeeded 78, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 58 s, completed Sep 22, 2015 7:31:12 PM

The browser tests are written using the Web Component Tester framework. The framework is customized for Polymer and also exposes the following utilities:

Tests are located in the test directory of each Polymer element in elements/.

Debugging Web Component Tester Test Failures

Here are some steps that are useful for debugging test failures:

  1. Execute web component tester in persistant mode from the root directory:
make testdev
  1. Add a debugger; line to the test you want to debug.

  2. Open a browser window and explicitly load the following url (Note: it is the same url that the test tool uses but all parameters have been removed from the end):

    http://localhost:2000/generated-index.html

  3. Open the developer tools for the browser and refresh. The tests should execute and then stop at the debugger; line. The code can now be debugged by stepping through it in the developer tools debugger.

Testing Against Python 2.7

You can run a tests against python 2.7 by adding an environment variable to your make calls.

# Run unit tests against 2.7
PYTHON=python2 make test

Element Documentation

Public elements and API are documented using Polymer suggested guidelines. Documentation can be run locally with the make docs target:

$ make docs
Moving static doc site content
Running hydrolysis to generate doc json
Running polybuild on docs.html
...
Serving docs at http://127.0.0.1:4001

Load the specified url in your browser to explore the documentation.

Other Topics

Initializing the Declarative Widgets extension

Before using the features provided by the Declarative Widgets extension in a notebook, the extension must first be initialized. The initialization process loads all dependencies and performs other required environment setup. Initialization is accomplished through a kernel specific API. Examples for each of the supported kernels is provided below. The initialization cell must precede the first cell in the notebook that makes use of Declarative Widgets features.

Python Initialization

import declarativewidgets as declwidgets

declwidgets.init()

Scala Initialization

// modify to IP and Port of this notebook server
%addjar http://localhost:8888/nbextensions/declarativewidgets/declarativewidgets.jar

import declarativewidgets._

initWidgets

R Initialization

library("declarativewidgets")
initWidgets()

Including a Web Component in a Notebook

The Declarative Widgets framework provides a mechanism to easily install and import a web component into a notebook. This mechanism is built on top of bower packages which are the current standard for publishing web components. Use the urth-core-import element upgraded link tag to include a web component element in a notebook.

%%html
<link rel='import' href='urth_components/paper-slider/paper-slider.html'
        is='urth-core-import' package='PolymerElements/paper-slider'>
<paper-slider></paper-slider>

The above code will first attempt to load paper-slider.html. If that fails, the specified package will be downloaded and installed on the server with bower install. The link href will then be requested again to load paper-slider.html and the related tag (paper-slider in this example) will render as is defined by the element.

To display some minimal details about the package loading in the developer console, specify the debug parameter.

Custom JavaScript API execution

Since Declarative Widgets initialization and import of web components is performed asynchronously, an elements upgraded JavaScript API may not be accessible upon execution of the cell. In order to ensure that the required API is available, make use of Urth.whenReady(function). This API will invoke the specified function only after prerequisites have been satisfied. The example code below demonstrates how to safely access the API of the custom urth-core-channel element:

%%html
<urth-core-channel name="mine" id="mychannel"></urth-core-channel>
%%javascript
var channel = document.getElementById('mychannel');

Urth.whenReady(function() {
    channel.set('myvar', 'myvalue');
});

declarativewidgets's People

Contributors

aluu317 avatar ankostis avatar dalogsdon avatar ellisonbg avatar flying-sheep avatar haobibo avatar j-towns avatar jhpedemonte avatar lbustelo avatar lull3rskat3r avatar parente avatar peller avatar poplav avatar rgbkrk avatar wellecks avatar wjsi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

declarativewidgets's Issues

User gets error feedback if the urth widgets are not configured correctly

Need a strategy to surface errors to the end user when widgets are not properly working.

One example is using an urth-core-function element and referring to a function that does not exist, or calling with incorrect parameters. We should display something near the cell to alert the user of the error.

Loading error when installing with `make sdist`

Hello,

I am trying to use the declarative widgets on my local ipython install. After running make sdist I can see that the widgets are installed in my user profile: ~/.ipython/nbextensions/urth_widgets/. However, I get the following error in my browser console:

[Log] Loaded extension: urth_dash_js/notebook/main (utils.js, line 29)
[Log] Loaded extension: urth_widgets/js/main (utils.js, line 29)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (webcomponents-lite.min.js, line 0)

Am I missing a step? Where is webcomponents-lite.min.js supposed to be?

Documentation rendering issues on IE and Safari

Noticed some rendering issues on IE and Safari:

IE (10, 11, Edge):

  • index.html - Navigation links (Docs, Repository) at top are not visible.
  • index.html - Hero element does not reflow correctly on small screens.
  • index.html - Column features are not honoring the max width.
  • docs.html - Does not render at all

Safari:

  • docs.html - Have to double click navigation elements in the left hand nav to get them to work. Single click just highlights the nav link.

User can watch channel data using a javascript event handler

We need a simple way to allow some javascript code be set as handler to changes to data on a channel. Right now the only way is to use a template element and use {{var}} syntax.

Say we have a python cell with:
channel("foo").set("x", 'new val')

We might should be able to support watching "x" change. something like
channle("foo").watch("x", function(){ //handler})

another option is to create a urth-core-channel element (Note singular channel) and have that be a point to binging event handlers.

Fix javascript unit test execution for pull requests

Our current build uses sauce labs to run the javascript unit tests. However, the test-js make target had to essentially be disabled on pull request builds since the sauce environment variables are not passed from Travis CI on pull request builds for security reasons. Travis CI does support running javascript tests locally through xfvb in the firefox browser. Problem is the javascript unit tests have a number of failures when run in firefox (but don't fail in chrome). The tests should be fixed to execute across browsers and the pull request build environment should be setup to execute them in xfvb on firefox through Travis CI.

Create a Channel inspector element to help user debug

@vinomaster just showed me a dashboard he created in which he added a template on the page to help him debug issues with channels. I think that this is a nice reusable pattern that should be encapsulated as an element.

I propose we create urth-tools-channel-inspector. The first go at this element will basically render the data in the channel in a simple table.

Add resize support (for dashboard)

Any widget that has resizable content should use iron-resizable-behavior to be properly notified when the window or element container resizes.

An example of this can be found in the paper-badge element.

This will allow widgets to resize properly in the dashboard view. Additionally, this will handle window resize, so an explicit window.onResize handler is not necessary.

  • Update urth-viz-table
  • Update urth-viz-chart
  • Create best practices doc detailing how Polymer elements should use iron-resizable-behavior

Scala support does not support serializing booleans

@vinomaster hit this problem on his demo notebook. If we do something like

channel().set("aVar", false)

or

channel().set("aVar", true)

They are getting sent to the browser as strings. We cannot then use them as expected in a <template is='dom-if'>.

The problem is https://github.com/jupyter-incubator/declarativewidgets/blob/master/kernel-scala/src/main/scala/urth/widgets/util/SerializationSupport.scala#L27 is missing a case of Boolean and converting to JsBoolean.

/cc @wellecks

Sync messages fire after widgets are detached

Widgets that use auto fire sync messages after each code execution completes. However, the callback used to fire these messages isn't removed when the widget is detached, resulting in extra sync messages.

E.g. re-run a cell that creates an urth-core-function with auto. After any further cell executions, two sync messages will be sent even though only one urth-core-function is attached.

Upgrade to Polymer v1.2

Polymer v1.2 introduced a change to Polymer.Collection which introduces a # prefix to the keys in the collection. This is breaking our ability to set and retrieve data channel values correctly and results in ~37 failed unit tests. The Polymer change was introduced in commit Polymer/polymer@85d8a3a

Since Polymer.Collection is not a documented interface and it appears we are not using it as intended, we should probably consider other alternatives to prevent this from breaking us again in the future.

Cannot install different version of already installed Polymer element

If I add a Polymer element to my notebook using:

<link rel="import" href="./static/urth_components/paper-toggle-button/paper-toggle-button.html"
    is="urth-core-import" package="PolymerElements/paper-toggle-button">

but then want to change to a specific version, like this:

<link rel="import" href="./static/urth_components/paper-toggle-button/paper-toggle-button.html"
    is="urth-core-import" package="PolymerElements/paper-toggle-button#v1.0.10">

it does not install the alternate version.

I presume it does a check for name only and does not install if that name is found?

urth-core-bind templates are not getting initialized with the data already on the channel

If we have a cell that does

from urth.widgets.widget_channels import channel
channel('c').set('user', 'Python')

Run that cell and then run a subsequent cell with code

%%html
<template is='urth-core-bind' channel='c'>
    <div>Hello from <span>{{user}}</span></div>
    Name: <input value='{{user::input}}'></input>
</template>

The value of variable c is not set in the <template>.

The expectation is that the <template> renders with any values that are already on the channel.

Thanks to @jhpedemonte and @dalogsdon

System Integration test suite

Our current testing strategy relies solely on unit test. We need to put together a suite of system test to verify main user level features of the widgets across multiple browsers.

Main concern:

  • urth-core-import installation of new elements
  • Proper results after Run-All cells
  • Selection capabilites

bower install of elements freezes server

Noticed yesterday when downloading threejs (which takes a while) that the bower install of elements completely freezes the server, such that I can't load or work on a different notebook. If possible, bower install should be handled asynchronously so as not to bog down everything else.

Should user explicitly init the declarative widget system

Currently this project adds an extension to Jupyter that initializes the Widget system on the Notebook page on load. This assumes that the kernel is ready to start accepting COM messages.

In the case of the Scala Kernel, the user must add the jar for the declarativewidget support and explicitly initialize the widget system (e.g. create a com open handler). To support this, we already have code in place on the JS side that runs after each code cell execution to check if the widget system is ready. There is a default of 10 tries (10 cells executed).

I propose that we reconsider how we are initializing and rather have the user explicitly initialize everything by running kernel code.

In python

from urth import widgets
widgets.init()

In scala

import urth._
widgets.init()

The init function would do the following:

  1. Make sure that the handler for COM opens on the kernel side is there (in python this is taken care by ipywidgets)
  2. Send JS code to the browser that would cause the browser side initialization to take place, basically import some elements and setup the data channel.

urth-viz-chart should allow coloring of series

When using urth-viz-chart I would like to supply color values for series in the chart. An example would be:

<urth-viz-chart type='bar' 
   datarows='[["a",8,5],["b",2,6]]' 
   columns='["Index","Series 1","Series 2"]' 
   series-colors='["green","red"]'
></urth-viz-chart>

'Run all' with urth-core-function auto does not execute

Load test notebook from https://gist.github.com/jhpedemonte/c650d0c608344d41723f

  1. Select 'Run all'. Notice that called1 and called2 are both zero, signifying that neither of the loadData functions was called.
  2. Clear and refresh page.
  3. Execute each cell individually. Notice that called1 remains zero, but called2 is now 1.

It appears that declaring an urth-core-function with the auto parameter separately (in another notebook cell) from a template that defines an argument to the function will execute automatically as intended.

If the urth-core-function is declared in the same template as an element that defines an argument to the function, the function does not execute.

Timing issue?

User can instantiate UI elements using kernel language

The idea would be to create a generic API that would allow building arbitrary elements. Sort of model against the DOM API and not at all specific to a set of widgets.

Something like:

elmt = createElement("urth-core-function")
elmt.set("ref", "something")
elmt.set("val", "{{var}}")

parent.appendChild(elmt)

parent.show()

And so on...

Enable running system test locally and on travis for pull request

We currently have a system-test target that is configured to run with SauceLabs. It looks to see if the SauceLabs env variables are set. It currently runs only on Travis as part of a merge into master.

We need to have the following 2 things:

  1. A way to run system test locally, without the use of SauceLabs and without having to start anything else to get it to work (i.e selenium). Should be model after make test-js.
  2. A way to run system tests on travis for PRs. This should be modeled aftet 'make test-js-remote`. In that target, the tests are fully ran on Travis using selenium and firefox.

I suggest that we use 2 targets as we do with make test-js and 'make test-js-remote'.

Python 2.7 Support

Hello,

I am trying to deploy the declarative widgets into our test environment. I am wondering: what is missing the get the declarative widgets to work on Python 2.7?

As of now, is Python 3 required only for user code, meaning that a Python 3 kernel in IPython running on 2.7 works? Or is Python 3 only needed for the notebook? Or both?

Thanks,
Thibaud

Docker images necessary for development are out of date

The cloudet/pyspark-notebook-bower-sparkkernel and cloudet/sbt-sparkkernel-image images used in the Makefile contain an old version of the Spark Kernel.

Crucially, this old version doesn't have the fix for defect 137 which is necessary for properly displaying the Scala widgets, e.g. in the urth-core-scala.ipynb examples notebook. As a result, it's difficult to introduce and test new features on the Scala widgets.

Extra comm message sent on Python Widget creation

The ipywidgets Widget class sends an update state message upon creation. Our widget system does not use the contents of this message, and it leads to unnecessary console logs and warnings, e.g. all of the below logs when the urth-core-channels is created:

screen shot 2015-10-01 at 2 26 29 pm

Allow import to notebook from sibling Polymer HTML file

I would like to create a standalone Polymer element file as a sibling to my current notebook, and import that element into the notebook. Couple of issues:

1. Relavitive Import

So far, I've found that doing the following will import the file:

<link rel="import" href="/files/my-folder/my-element.html">

I would prefer to be able to make this relative to the notebook, like so:

<link rel="import" href="./my-element.html">

The issue with that is that the notebook is loaded from /notebooks, but files are loaded from /files.

2. Imports within the element

How do I import dependencies from within my Polymer element? I tried the following:

<link rel="import" href="./static/urth_components/paper-toggle-button/paper-toggle-button.html"
    is="urth-core-import" package="PolymerElements/paper-toggle-button">
<link rel="import" href="./static/urth_components/iron-list/iron-list.html"
    is="urth-core-import" package="PolymerElements/iron-list">

but those don't load correctly. The issue is that the browser tries to load these relative to my Polymer element file (loaded from /files), whereas the location of the static/urth_components directory is in /notebooks/my-folder.

Timing issue between importing dependency and making use of it

Test notebook: https://gist.github.com/jhpedemonte/5193b20258742172778c

  1. Load test notebook.
  2. Run All.
  3. Try to interact with toggle button. Notice that it doesn't work. Also, it should have defaulted to 'on' (liveUpdate is true).
  4. Select cell with Polymer element and run that one again. Toggle button should now work as expected.

  5. Clear output and reload notebook.
  6. Run each cell one-by-one. Notice that toggle button works as expected.

  7. Clear output and reload notebook.
  8. Uncomment the 2 lines of Python code which sleep for 1 second.
  9. Run All. Notice that toggle button works as expected and defaults to 'on'.

User can change the signature of a function and the urth-core-function-element will react to the change

The urth-core-function element only receives an update message for signature at create time. If the user changes the function's signature and re-executes the cell... the urth-core-function element might get out of sync. This can lead to incorrect invocations.

A similar approach to what urth-core-dataframe does to update its value when it detects any cell execution would be a good first approach to trigger the sync request.

Once the element gets the new signature, all related properties (default values, valid state, etc.) should be updated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.