TODO
get secret_id from last Combine
get last Combine, ideally during constructor
get last bond value, during constructor or intial_value
Maybe
Bonds.incorporate_last_bond(
just_created::T,
previous::T,
previous_value_from_js::Any
)::T
with default (a,b)->a
UndefVarError: Slider not defined
Here is what happened, the most recent locations are first:
- macro expansionfrom This cell: line 125
- Show more...
Multiple expressions in one cell.
How would you like to fix it?
:fons
:hannes
:asdf_dsfsdf
UndefVarError: MultiCheckBox not defined
Here is what happened, the most recent locations are first:
- macro expansionfrom This cell: line 125
- Show more...
Another cell defining f and chosen_names contains errors.
Another cell defining f and chosen_names contains errors.
skip_as_script (generic function with 1 method)
@skip_as_script expression
Marks a expression as Pluto-only, which means that it won't be executed when running outside Pluto. Do not use this for your own projects.
@only_as_script (macro with 1 method)
Activating project at `~/.julia/environments/v1.7`
The package PlutoUI.jl could not load because it failed to initialize.
That's not nice! Things you could try:
- Restart the notebook.
- Try a different Julia version.
- Contact the developers of PlutoUI.jl about this error.
You might find useful information in the package installation log:
The package HypertextLiteral.jl could not load because it failed to initialize.
That's not nice! Things you could try:
- Restart the notebook.
- Try a different Julia version.
- Contact the developers of HypertextLiteral.jl about this error.
You might find useful information in the package installation log:
false
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
UndefVarError: Scrubbable not defined
Here is what happened, the most recent locations are first:
UndefVarError: NumberField not defined
Here is what happened, the most recent locations are first:
UndefVarError: Slider not defined
Here is what happened, the most recent locations are first:
UndefVarError: Scrubbable not defined
Here is what happened, the most recent locations are first:
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
UndefVarError: Dump not defined
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
true
missing
Combine
The package AbstractPlutoDingetjes.jl could not load because it failed to initialize.
That's not nice! Things you could try:
- Restart the notebook.
- Try a different Julia version.
- Contact the developers of AbstractPlutoDingetjes.jl about this error.
You might find useful information in the package installation log:
The package AbstractPlutoDingetjes.jl could not load because it failed to initialize.
That's not nice! Things you could try:
- Restart the notebook.
- Try a different Julia version.
- Contact the developers of AbstractPlutoDingetjes.jl about this error.
You might find useful information in the package installation log:
Combining bonds
The magic
Another cell defining HypertextLiteral contains errors.
RenderCallback(callback::Function, x::Any)
An HTML display passthrough of x
(displays the same content), but when it is displayed, a callback function is invoked. disable_callback!
can remove a callback.
UndefVarError: @htl not defined
Same as repr(MIME"text/html"(), x)
but the IOContext
is set up to match the one used by Pluto to render. This means that if the object being rendered wants to use AbstractPlutoDingetjes.is_supported_by_display
, they can.
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
PlutoUI.combine(render_function::Function)
Combine multiple input elements into one. The combined values are sent to @bind
as a single tuple.
render_function
is a function that you write yourself, take a look at the examples below.
Examples
🐶 & 🐱
We use the do
syntax to write our render_function
. The Child
function is wrapped around each input, to let combine
know which values to combine.
@bind values PlutoUI.combine() do Child
md"""
# Hi there!
I have $(
Child(Slider(1:10))
) dogs and $(
Child(Slider(5:100))
) cats.
Would you like to see them? $(Child(CheckBox(true)))
"""
end
values == (1, 5, true) # (initially)
The output looks like:
🎏
The combine
function is most useful when you want to generate your input elements dynamically. This example uses HypertextLiteral.jl for the @htl
macro:
function wind_speeds(directions)
PlutoUI.combine() do Child
@htl("""
<h6>Wind speeds</h6>
<ul>
$([
@htl("<li>$(name): $(Child(Slider(1:100)))</li>")
for name in directions
])
</ul>
""")
end
end
@bind speeds wind_speeds(["North", "East", "South", "West"])
speeds == (1, 1, 1, 1) # (initially)
# after moving the sliders:
speeds == (100, 36, 73, 60)
The output looks like:
Named variant
In the last example, we used Child
to wrap around contained inputs:
Child(Slider(1:100))
We can also use the named variant, which looks like:
Child("East", Slider(1:100))
When you use the named variant for all children, the bound value will be NamedTuple
, instead of a Tuple
.
Let's rewrite our example to use the named variant:
function wind_speeds(directions)
PlutoUI.combine() do Child
@htl("""
<h6>Wind speeds</h6>
<ul>
$([
@htl("<li>$(name): $(Child(name, Slider(1:100)))</li>")
for name in directions
])
</ul>
""")
end
end
@bind speeds wind_speeds(["North", "East", "South", "West"])
speeds == (North=1, East=1, South=1, West=1) # (initially)
# after moving the sliders:
speeds == (North=100, East=36, South=73, West=60)
md"The Eastern wind speed is $(speeds.East)."
The output looks like:
Why?
You can make a new widget!
You can use combine
to create a brand new widget yourself, by combining existing ones!
In the example above, we created a new widget called wind_speeds
. You could put this function in a package (e.g. WeatherUI.jl
) and people could use it like so:
import WeatherUI: wind_speeds
@bind speeds wind_speeds(["North", "East"])
In other words: you can use combine
to create application-specific UI elements, and you can put those in your package!
Difference with repeated @bind
The standard way to combine multiple inputs into one output is to use @bind
multiple times. Our initial example could more easily be written as:
md"""
# Hi there!
I have $(@bind num_dogs Slider(1:10)) dogs and $(@bind num_cats Slider(5:10)) cats.
Would you like to see them? $(@bind want_to_see CheckBox(true))
"""
The combine
function is useful when you are generating inputs dynamically, like in our second example. This is useful when:
The number of parameters is very large, and you don't want to write
@bind parameter1 ...
,@bind parameter2 ...
, etc.The number of parameters is dynamic! For example, you can load in a table in one cell, and then use
combine
in another cell to select which rows you want to use.
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
Examples
UndefVarError: _combine not defined
Here is what happened, the most recent locations are first:
- combine
(f::Function; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) from Other cell: line 149"""
combine(f::Function; kwargs...) = _combine(f; kwargs...)
- Show more...
values (generic function with 5 methods)
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
UndefVarError: speeds not defined
Here is what happened, the most recent locations are first:
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
UndefVarError: speeds_named not defined
Here is what happened, the most recent locations are first:
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
UndefVarError: together not defined
Here is what happened, the most recent locations are first:
UndefVarError: rb not defined
Here is what happened, the most recent locations are first:
Tests
Initial value & transform
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
UndefVarError: it2vs not defined
Here is what happened, the most recent locations are first:
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
Should be [[missing, sin], [50, sin]]
UndefVarError: itvs not defined
Here is what happened, the most recent locations are first:
UndefVarError: @htl not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:115
- macroexpandfrom expr.jl:114
UndefVarError: ☎️c not defined
Here is what happened, the most recent locations are first:
UndefVarError: ☎️s not defined
Here is what happened, the most recent locations are first:
Combine inside combine
UndefVarError: _combine not defined
Here is what happened, the most recent locations are first:
- combine
(f::Function; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) from Other cell: line 149"""
combine(f::Function; kwargs...) = _combine(f; kwargs...)
- Show more...
Another cell defining cb1 contains errors.
Another cell defining cb1 contains errors.
Another cell defining cb1 contains errors.