Import PlutoTables
and other useful packages:
👀 Reading hidden code
using PlutoTables
👀 Reading hidden code
using AccessorsExtra
👀 Reading hidden code
using PlutoUIExtra
👀 Reading hidden code
using IntervalSets
👀 Reading hidden code
using Unitful
👀 Reading hidden code
using StaticArrays
👀 Reading hidden code
using LinearAlgebra: norm
👀 Reading hidden code
👀 Reading hidden code
Define a nested struct that we'll create tabular UI for. This is standard Julia code, nothing specific to PlutoTables
.
👀 Reading hidden code
begin
struct ExpModel{A,B}
scale::A
shift::B
end
struct SumModel{T <: Tuple}
comps::T
end
(m::ExpModel)(x) = m.scale * exp(-(x - m.shift)^2)
(m::SumModel)(x) = sum(c -> c(x), m.comps)
end
👀 Reading hidden code
Create an instance of this struct:
👀 Reading hidden code
2.0
5.0
0.5
2.0
0.5
8.0
mod₀ = SumModel((
ExpModel(2., 5.),
ExpModel(0.5, 2.),
ExpModel(0.5, 8.),
))
👀 Reading hidden code
Now, let's see some examples of PlutoTables
UIs and layouts to modify this object.
Target values are specified as Accessors
optics, and each is associated with a PlutoUI
input element using the Pair
syntax: optic => input
.
Note how the syntax is similar to optimization problem specifications in the AccessibleOptimization
package.
👀 Reading hidden code
Edit some specific values of interest:
👀 Reading hidden code
_.comps[1].scale | |
_.comps[1].shift | |
_.comps[3].shift |
@bind mod1 ColumnInput(mod₀, (
(@o _.comps[1].scale) => Slider(0:5., show_value=true),
(@o _.comps[1].shift) => Slider(0:5., show_value=true),
(@o _.comps[3].shift) => Slider(0:10., show_value=true),
))
👀 Reading hidden code
2.0
5.0
0.5
2.0
0.5
8.0
mod1
👀 Reading hidden code
Edit all scales and shifts:
👀 Reading hidden code
_.comps[∗].scale | |
_.comps[∗].shift | |
@bind mod2 ColumnInput(mod₀, (
(@o _.comps[∗].scale) => Slider(0..5),
(@o _.comps[∗].shift) => Slider(0..10),
))
👀 Reading hidden code
2.0
4.99
0.501
2.0
0.501
8.0
mod2
👀 Reading hidden code
Show numbers, keys, or any other information using context-optics from
AccessorsExtra
:
👀 Reading hidden code
Loading more cells...