Interactive Widgets in IJulia

IPython 2.0 introduced interactive widgets, which are basically:

  • Javascript widgets (sliders, buttons, etcetera)
  • A communications protocol for the widgets to talk to the kernel
  • A Python interface to create and manipulate these.

Thanks to fantastic work by a Google Summer of Code student, Shashi Gowda, the same features are accessible from a Julia interface.


In [1]:
using Interact



In [2]:
@manipulate for n in 1:100
    rand(n,n)
end


Out[2]:
50x50 Array{Float64,2}:
 0.0765897   0.519796    0.953122    …  0.677004   0.465757  0.129966  
 0.138386    0.0793059   0.433054       0.627591   0.896409  0.552414  
 0.0045352   0.130881    0.53402        0.994508   0.854956  0.652335  
 0.54617     0.00730421  0.513664       0.566419   0.266489  0.168505  
 0.465302    0.418167    0.315846       0.335354   0.601254  0.438266  
 0.676203    0.513862    0.531791    …  0.994509   0.751153  0.741091  
 0.695115    0.76464     0.82935        0.534769   0.332754  0.56495   
 0.0210419   0.463383    0.925921       0.923421   0.523593  0.981061  
 0.884246    0.733113    0.72252        0.705558   0.134037  0.0495707 
 0.470805    0.384316    0.976076       0.280249   0.329326  0.812063  
 0.138351    0.766956    0.795017    …  0.965332   0.706273  0.312587  
 0.00771362  0.273022    0.977369       0.346318   0.726189  0.777591  
 0.496053    0.232746    0.854075       0.0674143  0.4009    0.898487  
 ⋮                                   ⋱                                 
 0.556335    0.831684    0.194122       0.711793   0.824205  0.346121  
 0.619373    0.457818    0.338351       0.428709   0.20042   0.998742  
 0.616902    0.622503    0.898938    …  0.461968   0.195278  0.0927902 
 0.757413    0.683864    0.37314        0.487296   0.689677  0.333718  
 0.14964     0.684207    0.80815        0.831772   0.24402   0.245035  
 0.728672    0.418792    0.665256       0.11393    0.441472  0.57802   
 0.677289    0.495151    0.97746        0.399716   0.716588  0.101503  
 0.475157    0.112981    0.833662    …  0.0808928  0.776474  0.803877  
 0.8442      0.0951176   0.584663       0.930179   0.543812  0.137481  
 0.811281    0.960377    0.00310698     0.680671   0.479665  0.00207537
 0.780725    0.845177    0.875328       0.131043   0.64739   0.183616  
 0.614355    0.569389    0.582262       0.661829   0.131525  0.298459  

In [3]:
using Color
@manipulate for r in 0:0.1:1, g in 0:0.1:1, b in 0:0.1:1, n in 1:100
    linspace(RGB(0,0,0), RGB(r,g,b), n)
end


Out[3]:

In [4]:
using PyPlot


INFO: Loading help data...

In [5]:
x = linspace(0,10,1000)
clf()
f = figure()
@manipulate for α = 1:0.1:4, β = 1:0.1:4, leg="a funny plot"
    withfig(f) do
        plot(x, cos(α*x + sin(β*x)))
        legend([leg])
    end
end


Figure(PyObject <matplotlib.figure.Figure object at 0x7f88267aed10>)
Out[5]:

In [6]:
using SymPy
x = sym"x"
@manipulate for n=0:20
    latex(SymPy.diff(sin(x^2), x, n))
end


Warning: imported binding for transpose overwritten in module __anon__
Warning: ignoring conflicting import of Gadfly.plot into SymPy
Out[6]: