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.771028   0.551472   0.314047   …  0.130576   0.533205   0.927449 
 0.424816   0.906623   0.393111      0.877565   0.89651    0.883033 
 0.506155   0.417193   0.914064      0.687512   0.702219   0.367159 
 0.393464   0.890952   0.664509      0.442503   0.803283   0.267329 
 0.298762   0.110954   0.10228       0.381457   0.405499   0.405366 
 0.402276   0.893652   0.132753   …  0.456364   0.0849522  0.455111 
 0.950202   0.20826    0.513657      0.937883   0.809896   0.8217   
 0.752829   0.515662   0.658611      0.0689324  0.888209   0.22828  
 0.234646   0.611798   0.834422      0.481401   0.503802   0.728088 
 0.187468   0.581144   0.678771      0.657986   0.539115   0.353525 
 0.160902   0.144047   0.199838   …  0.737959   0.840086   0.786123 
 0.333793   0.693698   0.775659      0.820311   0.926053   0.891198 
 0.557649   0.186607   0.547599      0.178013   0.709443   0.61606  
 ⋮                                ⋱                                 
 0.982145   0.30881    0.0850956     0.861075   0.666444   0.0404642
 0.0156565  0.318372   0.715466      0.244769   0.861265   0.545043 
 0.83222    0.458816   0.12603    …  0.295398   0.113606   0.536485 
 0.576201   0.983607   0.633747      0.501623   0.543863   0.557923 
 0.66451    0.61527    0.377591      0.113888   0.827206   0.960024 
 0.353578   0.521753   0.156359      0.407187   0.39467    0.112012 
 0.15143    0.902195   0.473292      0.813092   0.543734   0.404927 
 0.60293    0.454086   0.240309   …  0.921112   0.833199   0.535652 
 0.810557   0.23405    0.621566      0.481397   0.280802   0.0163834
 0.593772   0.0991918  0.688917      0.0453414  0.0013039  0.0055148
 0.664053   0.89177    0.858967      0.643983   0.997811   0.780995 
 0.821871   0.960463   0.979437      0.351703   0.295269   0.733468 

In [5]:
using Colors
@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.0,0.0), RGB(r,g,b), n)
end


Out[5]:

In [6]:
using PyPlot


INFO: Loading help data...

In [7]:
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 0x7f38228f5f10>)
Out[7]:

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


Out[14]: