In [5]:
%addjar http://localhost:8888/nbextensions/declarativewidgets/urth-widgets.jar


Starting download from http://localhost:8888/nbextensions/declarativewidgets/urth-widgets.jar
Finished download of urth-widgets.jar

In [6]:
import declarativewidgets._
initWidgets



In [7]:
import declarativewidgets.WidgetChannels.channel

Inter-cell binding


In [8]:
declarativewidgets.WidgetChannels


Out[8]:
declarativewidgets.WidgetChannels$@6296669

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


Out[9]:

In [10]:
%%html
<template is='urth-core-bind' channel='a'>
    <div>Hello again from <span>[[user]]</span></div>    
</template>


Out[10]:

Channels and sliders

import paper-slider widget


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


Out[11]:

bind the value for x to channel A


In [21]:
%%html
<template is='urth-core-bind' channel='ch_A'>  
    <span>Channel A</span>    
    <table>
        <tr>    
            <td>
                <paper-slider 
                    min="10" 
                    max="100" 
                    step="1" 
                    value="[[x]]"/>
            </td>
            <td>
                <span>[[x]]</span>
            </td>
        </tr>
    </table>    
</template>


Out[21]:

In [ ]:


In [33]:
%%html
<template is='urth-core-bind' channel='ch_A'>
    <div>Hello again from <span>[[x]]</span></div>    
</template>


Out[33]:

Reactive machinery

import transitive RxScala dependency


In [22]:
%AddDeps io.reactivex rxscala_2.10 0.26.1 --transitive


Marking io.reactivex:rxscala_2.10:0.26.1 for download
Preparing to fetch from:
-> file:/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/toree_add_deps6237874973947631549/
-> https://repo1.maven.org/maven2
-> New file at /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/toree_add_deps6237874973947631549/https/repo1.maven.org/maven2/io/reactivex/rxscala_2.10/0.26.1/rxscala_2.10-0.26.1.jar
-> New file at /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/toree_add_deps6237874973947631549/https/repo1.maven.org/maven2/io/reactivex/rxjava/1.1.1/rxjava-1.1.1.jar

In [23]:
import java.util.concurrent.TimeUnit._
import scala.concurrent.duration.Duration
import rx.lang.scala.{Observer, Subscription, Observable}
import declarativewidgets.WidgetChannels.channel

Start a timer with 1 sec interval that posts to the channel "ch_A", bound to the paper-slider


In [36]:
val s1 = Duration(1, SECONDS)

val timer_sub = 
    Observable.
        interval(s1, s1).
        subscribe(onNext = (l) => channel("ch_A").set("x", l.toString))

In [37]:
timer_sub.unsubscribe()

Channel fn experiment


In [14]:
%%html
<template is='urth-core-bind' channel='ch_FN'>
    <div>Hello again <span>[[f]]</span></div>    
</template>


Out[14]:

In [15]:
channel("ch_FN").set("f", (i: Int) => i+1)

Dynamic magic


In [18]:
val magic_sub = 
    Observable.
        interval(s1, s1).
        subscribe(onNext = (l) => kernel.magics.html(s"<h1>a title</h1><p>hello: $l</p>"))

In [39]:
val l = "test"
kernel.magics.html(s"<h1>a title</h1><p>hello: $l</p>")


Out[39]:

a title

hello: test


In [ ]: