juliagizmos / interact.jl Goto Github PK
View Code? Open in Web Editor NEWInteractive widgets to play with your Julia code
License: Other
Interactive widgets to play with your Julia code
License: Other
i made togglebuttons based on the same options except previous togglebuttons selection.
ff = ["F1","F2","F3","F4"]
f1 = togglebuttons(ff)
display(f1)
f2 = lift(x->togglebuttons(filter(a->a!=x,ff)),f1)
display(f2)
display(f1.signal)
display(f2.value.signal)
second togglebuttons could be correctly lifted whenever first togglebuttons was selected, but the order of togglebuttons wasn't the same order of the filtered options.
Also, when first togglebuttons was selected to other than F1, the second togglebuttons could not give the F1 output.
is there anything i am missing?
If I do
@manipulate for n=1:5
html("$n")
end
the new outputs get appended to the output cell as I drag the slider, instead of replacing the old output.
I would like to put constraints on my inputs making them either co-dependent or at least validate them take the following Gadfly plot
@manipulate for μ in -5:5, σ in 0:5, min in -10:0, max in 0:10
dist = Normal(μ, σ)
plot(x -> pdf(dist,x), min, max)
end
I would like to validated an input like this.
@manipulate for μ in -5:5, σ = 10, min = -10 , max = 10 | max >= min | σ >= 0
dist = Normal(μ, σ)
plot(x -> pdf(dist,x), min, max)
end
Is there a way so that @manipulate
will work in the nbviewer? I like to post my notebooks online so that those without IJulia installed can view them.
For example:
http://nbviewer.ipython.org/github/sisl/aa228-notebook/blob/master/07-Games.ipynb
Perhaps a variation of @manipulate
can cache the output as SVG/html/etc.?
This is quite a useful function; it would be nice to export it.
It might also be nice to change its API to:
widget(foo; label="", kws...)
i.e. changing label
to a keyword option and passing any additional keywords through to the corresponding widget constructor (for #16).
Everything else seems to work fine, just not HTML outputs. I can reproduce this using the introduction notebook from the docs, but even a simple html("<b>Hi</b>")
fails. I'm on Julia master, IPython 2.3.1 and see the same behavior both in Firefox and Chromium. From the inspector, you can see that it correctly sets the output cell's type to html. In the js console, I can see something being null
.
The 404 not found you see is unrelated as it's just the source-map which the inspector looks for.
Any ideas?
Does interact have an output widget for just plain text? I didn't see it in widgets.jl. Currently, I'm just returning a string, but that's not as nice because it show
s rather than print
s.
It could be very nice if there also were an @animation
macro, since the tool works on a lot of different plots, it is not fast but it's versatile. It could turn the first range in @manipulate
to the time dependent variable and then have a Play, Pause, Prev, Next botton to interaction.
edit: @ivarne - quoting macros
I don't see why it you have a separation between InputWidget
and Input
, i.e. you create a widget and then attach!
an input to it.
Why not simply make the InputWidget
a type of Signal
? Then I could simply do e.g.
s = Slider(....)
lift(x -> RGB(x,x,x), s)
The example notebook could be so much more delightful with a notebook that has more of a story.
I tried the example notebook in IPython 2.1.0, and it doesn't seem to work. I can create a slider, but then signals based on it don't update.
Does Interact require a newer IPython? If so, please mention this in the README.
(Though it's confusing since I though interactive widgets were in IPython 2....)
@manipulate for i = 1:10
i > 7 ? i * "2" : 2*i
end
instead of throwing an exception when the slider is dragged past 7
, it just silently doesn't display an update.
In https://github.com/JuliaLang/Interact.jl/blob/master/doc/notebooks/01-Introduction.ipynb
The last cell calling lift with the keyword argument input
x = slider(0:.1:2pi, label="x")
y = lift(v -> slider(-1:.05:1, value=sin(v), input=fx, label="f(x)"), x)
map(display, (x,y));
gives the following error
unrecognized keyword argument "input"
while loading In[22], in expression starting on line 2
in anonymous at In[22]:2
Looks like 3.0 breaks support for @manipulate
, which is a shame.
@manipulate for i=1:10
println(i)
end
does not work, leading to confused users (#40, and #26). One possible fix:
Transform manipulate blocks so that they push a display to the stack, and pop it at the end. Then take everything that got printed and the value of the last expression and push them to the front-end. This will require implementing some kind of containers so that values of different mime types can be displayed in the same cell output.
Second possible fix:
Since the only use of println / display is to display multiple things as a result of the same @manipulate
block, it could be OK to just somehow implement containers and not care about side effects.
The initial output, e.g. a figure, apparently moves (changes position) slightly once the slider is moved.
Interact.jl
is great, thanks!
But...
using Interact
using PyPlot
function g(N)
PyPlot.plot(rand(N), rand(N), "o")
end
@manipulate for N in 1:100
g(N)
end
gives a single plot that is not updated when the slider is moved.
However, executing another empty code cell shows all the other plots that were generated by the @manipulate
command!
julia> versioninfo()
Julia Version 0.3.1-pre+17
Commit a3e7c04 (2014-08-25 18:52 UTC)
Platform Info:
System: Darwin (x86_64-apple-darwin13.0.0)
CPU: Intel(R) Core(TM) i7-2677M CPU @ 1.80GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3
Right now, signal of PyPlot plots do not update. Instead, updates get drawn on to the same plot in the kernel and the new plot appears out of the blue when executing any other cells.
Unlike @lift
(which can probably be deleted now that we have @manipulate
, by the way), I think you can write @manipulate
so that it doesn't use eval
. Using eval
is always a bad idea in a macro, because it makes it extremely brittle, e.g. you can't use the macro inside a function. Following the syntax in #8, just have the macro transform:
@manipulate for x1=params1, x2=params2
expression
end
into something like
let x1=widget(params1, label="x1"), x2=widget(params2, label="x2")
display(x1)
display(x2)
lift((x1,x2) -> expression, x1, x2)
end
where widget
is an overloaded function that creates a default widget (or anything that can be passed to signal
) from the parameters of a given type. e.g. widget(::Bool)
will create a checkbox, widget(::Range)
will create a slider, etcetera.
This has the additional advantage that the available widgets for @manipulate
are no longer hard-coded. Any package can provide additional widgets just by overloading widget
.
Interact.widget(1:10)
gives:
`__slider#17__` has no method matching __slider#17__(::Float64, ::Input{Float64}, ::ASCIIString, ::UnitRange{Int64})
while loading In[23], in expression starting on line 1
in widget at /Users/stevenj/.julia/Interact/src/manipulate.jl:5
I would like to draw my own widget using compose and have it call a callback (read fire a signal), e.g. when I click on a circle in my picture. I tried to do this, but I failed to get a custom widget to work, so I'd also appreciate a tutorial on how to write custom widgets (maybe this use case can serve as one).
cc @dcjones
Since you fixed the last issue so quickly, I figured I'd give you more⸮
Using Julia master, IPython 2.3.1, latest Interact.jl and Gadfly 0.3.10 (latest), I have problems with the Gadfly plots in the "03-Interactive Diagrams and Plots" documentation notebook.
In Firefox 34, the plot's content doesn't show, the axes do. The js-console has one potentially related output "Empty string passed to getElementById().":
In Chromium 39, the plot shows correctly, but any interaction doesn't update the plot, though the Kernel indicator shows "Kernel Busy" for a brief period after any interaction. Seemingly no interesting output in the js-console:
Using Gadfly itself without any @manipulate
works perfectly fine in the exact same notebook, which makes me think it's an Interact.jl issue.
I have previously had Interact working, but had not used it in a while.
The sliders are created, but do not update the output of the cells: the initial output is fixed.
This is with a fresh .julia
directory and fresh checkouts of IJulia and Interact.
I have no idea where to start looking for problems...
Julia Version 0.3.6-pre+43
Commit 2dfde6b* (2015-01-22 20:39 UTC)
Platform Info:
System: Darwin (x86_64-apple-darwin14.0.0)
CPU: Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3
It would be more natural to use a range object to give the slider range, and also this seems like a good candidate for keyword options. i.e.
Slider{T<:Number}(r::Range{T}; label="", value::T=median(r)) = ...
Using a range internally will also allow you to take advantage of the cleverness in FloatRange
in constructing roundoff-resistant floating-point ranges.
I would similarly use keywords for other widgets, e.g.
Checkbox(label::String; value=false) = ...
RadioButtons{T}(options::Labeled{T}...; label::String="", value::T=options[1].value) = ...
RadioButtons{T}(options::T...; kws...) = RadioButtons(map(Labeled, options)...; kws...)
Dropdown{T}(options::Labeled{T}...; label::String="", value::T=options[1].value) = ...
Dropdown{T}(options::T...; kws...) = Dropdown(map(Labeled, options)...; kws...)
I would also tend to use Label
instead of Labeled
. It is shorter, it follows the noun convention for types, and it avoids the controversy of spelling "labeled" vs. "labelled".
It might be more Julian to have @manipulate foo(x) for x in ...
, i.e. with a for
keyword.
doing using Interact; dropdown(["one","two","three"])
in IJulia, and then changing the dropdown selection, seems to make IPython ignore shift-enter in subsequent cells; or rather it treats it just as "enter" and inserts an ordinary newline in the cell.
(I can still run subsequent cells, but only by clicking the "run" button in the toolbar.
So, somehow the dropdown widget seems to be altering IPython's keybindings. (@Carreau?)
I have slightly unorthodox notebook setup: IJulia is running bound to localhost and is then being served to the world over HTTPS via an nginx instance:
[IJulia:8998] <----> [nginx:443] <----> [browser]
Everything works great, EXCEPT Interact.jl
and hence, @manipulate
. I checked my javascript console for weird errors and I didn't really see anything suspicious, so I was hoping that one of you guys would be able to help me debug this. My guess is that I am somehow screwing up the websocket connection by having it go through the HTTPS transition, but I don't really know what's going on under the hood here. My nginx
config is apparently enough to get basic code execution working, and enough to pop up the widgets, but once I try to, well, manipulate them, nothing happens. Here's my nginx
config:
server {
listen 443 ssl;
server_name ee590_julia.davinci.cs.washington.edu;
ssl_certificate davinci.cs.washington.edu.crt;
ssl_certificate_key davinci.cs.washington.edu.key;
location / {
proxy_pass http://localhost:8998;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Origin "";
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
}
If you want to take a look at the actual notebook, I can mail you the password to login. This is on Julia 0.3.1
with the latest packages.
You defined widget(x::Bool, label="") = checkbox(x, label="")
but there is no Checkbox(::Bool)
contructor. Adding checkbox(x::Bool; kws...) = checkbox(; value=x, kws...)
seems like it should do the trick. But probably it's cleaner to just define:
widget(x::Bool, label="") = checkbox(value=x, label=label)
(Also note that you accidentally were deleting the label.)
Is there any way to control where widgets will appear when displaying more than one of them? E.g. say I wanted to have multiple checkboxes side by side. They seem to stack vertically by default. Something like hstack in Gadfly would be great. I guess this is somewhat related to #38 which I also would very much like to see.
Would be happy to have a bash at it but not sure really where to start.
Ta!
Is Interact known not to work with ipython 3.0-dev?
the following example runs on ipython 2.3, but does not produce any output using ipython 3.0-dev:
using Interact, Gadfly
@manipulate for y in 1:5
plot(x -> x^y, -5, 5)
end
Is this ready to add to METADATA so that we can just do Pkg.add("Interact")
?
Neither the value of n nor the plot is updated with the following code where n is selected from a list (which gives boxes to select from):
using Interact
using PyPlot
f = figure()
@manipulate for n in [3, 5, 7]
withfig(f) do
display(n)
plot(rand(n), "o-")
end
end
julia> versioninfo()
Julia Version 0.3.1-pre+17
Commit a3e7c04 (2014-08-25 18:52 UTC)
Platform Info:
System: Darwin (x86_64-apple-darwin13.0.0)
CPU: Intel(R) Core(TM) i7-2677M CPU @ 1.80GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3
Here are two notebooks
https://gist.github.com/jiahao/97c2050d369812a4416f
and
which, as far as I can tell, have identical content. However the Interact widget in the first notebook doesn't work for me, but works in the second notebook, which was created by pasting each cell from the first notebook into a new notebook.
We should probably find a better way to collect examples. Meanwhile, let's use this issue to show off cool things you create with Interact. Code snippets, nbviewer / github links are all welcome.
Here's something to start this off :)
# (phantom) particles in a box
using Reactive, Interact
using Color, Compose
box(x) = let i = floor(x)
i%2==0 ? x-i : 1+i-x
end
colors = distinguishable_colors(10, lchoices=[82.])
dots(points) = [(context(p[1], p[2], .05, .05), fill(colors[i%10+1]), circle())
for (i, p) in enumerate(points)]
@manipulate for t=timestamp(fps(30)), add=button("Add particle"),
velocities = foldl((x,y) -> push!(x, rand(2)), Any[rand(2)], add)
compose(context(),
dots([map(v -> box(v*t[1]), (vx, vy)) for (vx, vy) in velocities])...)
end
I'm not sure what these widget types are for (they seem like outputs rather than inputs?), but it seems wrong to me. It seems like we should be using the writemime
functionality instead.
That is, if you want to display an object x
, you act just like display(x)
: you check mimewritable("text/html", x)
etcetera to see what output formats it supports.
I find that first(range)
is typically not the default that I want.
PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their tests (if available) on both the stable version of Julia (0.3) and the nightly build of the unstable version (0.4). The results of this script are used to generate a package listing enhanced with testing results.
N/A - new package.
Package doesn't load.
Package doesn't load.
means that PackageEvaluator did not find tests for your package. Additionally, trying to load your package with using
failed.
This issue was filed because your testing status became worse. No additional issues will be filed if your package remains in this state, and no issue will be filed if it improves. If you'd like to opt-out of these status-change messages, reply to this message saying you'd like to and @IainNZ will add an exception. If you'd like to discuss PackageEvaluator.jl please file an issue at the repository. For example, your package may be untestable on the test machine due to a dependency - an exception can be added.
Test log:
>>> 'Pkg.add("Interact")' log
INFO: Cloning cache of Interact from git://github.com/shashi/Interact.jl.git
INFO: Cloning cache of React from git://github.com/shashi/React.jl.git
INFO: Installing DataStructures v0.3.1
INFO: Installing Interact v0.1.2
INFO: Installing React v0.1.6
INFO: Package database updated
>>> 'using Interact' log
ERROR: JSON not found
in require at loading.jl:47
in include at ./boot.jl:245
in include_from_node1 at ./loading.jl:128
in include at ./boot.jl:245
in include_from_node1 at ./loading.jl:128
in reload_path at loading.jl:152
in _require at loading.jl:67
in require at loading.jl:51
in include at ./boot.jl:245
in include_from_node1 at loading.jl:128
in process_options at ./client.jl:285
in _start at ./client.jl:354
in _start_3B_1718 at /home/idunning/julia03/usr/bin/../lib/julia/sys.so
while loading /home/idunning/pkgtest/.julia/v0.3/Interact/src/html_setup.jl, in expression starting on line 3
while loading /home/idunning/pkgtest/.julia/v0.3/Interact/src/Interact.jl, in expression starting on line 84
while loading /home/idunning/pkgtest/.julia/v0.3/Interact/testusing.jl, in expression starting on line 2
Julia Version 0.3.0-rc4+4
Commit bab9636 (2014-08-20 18:47 UTC)
Platform Info:
System: Linux (x86_64-unknown-linux-gnu)
CPU: Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3
>>> test log
no tests to run
>>> end of log
# You will need:
# Interact.jl
# JuMP.jl
# An LP solver: Clp.jl
# GLPKMathProgInterface.jl
# ECOS.jl ...
using Interact
using JuMP
# Create model with initial default knapsack capacity
# Create model with initial default knapsack capacity
knap = Model()
@defVar(knap, 0 <= x[1:3] <= 1)
@setObjective(knap, Max, 5x[1] + 10x[2] + 7x[3])
knap_con = @addConstraint(knap, 3x[1] + 6x[2] + 3x[3] <= 1)
knap
# Now vary the right-hand-side and see how the solution changes
@manipulate for capacity in 0:12
chgConstrRHS(knap_con, capacity) # Change the capacity
display(knap) # Display model
solve(knap) # Resolve
getValue(x) # Display solution
end
IPython widgets have attributes such as label
, orientation
, readout
, etc. It would be nice to have an options
field in Widgets which is of a composite type. A nice API through kwargs would be good. It would be fantastic if this field is allowed to be a Signal and lift
is obviated.
cc: @StefanKarpinski
I think that the @manipulate
macro etc. is likely to be pretty central to the IJulia experience; in fact, I'm inclined to have IJulia REQUIRE React and Interact now that things are shaping up. It would therefore be good to move these packages to JuliaLang so that more maintainers are available in the future.
One thing that I don't like about the current @manipulate
(besides #11 and #8) is that it relies upon display
side effects. Not only does this mean that it can't be easily used in a functional context, but it also means that the widgets may be displayed out-of-order (since zeromq does not guarantee that messages arrive in-order, although they usually do in practice) (not true: zmq apparently does guarantee order).
It would be nice to be able to return a single object from @manipulate
that encapsulates both the widgets and the displayed signal result, such that calling display
on it will display all of them together.
Unfortunately, this may be a bit tricky to implement. Ideally you would write a writemime
method that stitches all the data together. But it's not so easy to stitch together, e.g. text/html widgets and text/latex signal output. You could overload display
(to call display
on the widgets and signals separately) instead of writemime
, but this could be somewhat fragile and also wouldn't solve the in-order issue.
I'm not really clear on why these are separate packages, since Interact seems to require IJulia/IPython.
With IPython 2.1.0,
s = Slider(0:0.01:1, label="Slider x:")
display(s)
lift(x -> x^2, s)
initially outputs [Lift{Float64}] 0.0
, but as soon as I drag the slider it changes to just the value (e.g. 0.0529
).
This is a bit jarring; the initial display and the display when you drag the slider should be of the same form.
using PyPlot
@manipulate for p in 1:0.01:2
LaTeXString("\$x^{$p}\$")
end
initially outputs via LaTeX, but as soon as I drag the slider it switches to text/plain
output.
(LaTeXString
is just a type defined in PyPlot that defines a writemime
method to interpret the string as text/latex
.)
I have come to prefer having lower cased functions that return values of their camel cased types. This looks like a pretty common pattern in Julia. e.g. string, int, plot, etc. This has also been the pattern used in Gadfly. Better to do this now than have this as a breaking change later.
Hello! I'd like to be able to have widgets display based on values of signals.
Here is an attempt, should it work and allow me to choose the widget that gets displayed?
widget_choice = togglebuttons(["slider","checkbox"], label="choose a widget")
display(widget_choice)
slider_to_show = slider(1:10; label="killr slider")
checkbox_to_show = checkbox(true; label="my new checkcheck")
widget_chosen = lift(x->x=="slider"? slider_to_show : checkbox_to_show, Widget, widget_choice)
display(widget_chosen)
It starts out fine, initially showing the slider, when I choose checkbox I get this:
If the checkbox is the default in the togglebuttons and then I choose slider, this is the outcome:
Julia is 0.3.3, Interact is 0.1.6, Reactive is 0.1.10
Cheers.
IPython widgets have attributes such as label
, orientation
, readout
, etc. It would be nice to have an options
field which is of a composite type in the widgets and provide a nice API through kwargs. It would fantastic if this field is allowed to be a Signal as well.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.