To be able to edit code and run cells, you need to run the notebook yourself. Where would you like to run the notebook?

This notebook takes about 3 minutes to run.

In the cloud (experimental)

Binder is a free, open source service that runs scientific notebooks in the cloud! It will take a while, usually 2-7 minutes to get a session.

On your computer

(Recommended if you want to store your changes.)

  1. Copy the notebook URL:
  2. Run Pluto

    (Also see: How to install Julia and Pluto)

  3. Paste URL in the Open box

Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

Author 1

Import PlutoTables and other useful packages:

👀 Reading hidden code
210 μs
using PlutoTables
👀 Reading hidden code
413 ms
using AccessorsExtra
👀 Reading hidden code
205 μs
using PlutoUIExtra
👀 Reading hidden code
74.0 ms
using IntervalSets
👀 Reading hidden code
129 μs
using Unitful
👀 Reading hidden code
347 ms
using StaticArrays
👀 Reading hidden code
430 ms
using LinearAlgebra: norm
👀 Reading hidden code
206 μs

👀 Reading hidden code
68.8 μs

Define a nested struct that we'll create tabular UI for. This is standard Julia code, nothing specific to PlutoTables.

👀 Reading hidden code
229 μs
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
4.5 ms

Create an instance of this struct:

👀 Reading hidden code
168 μs
mod₀ = SumModel((
ExpModel(2., 5.),
ExpModel(0.5, 2.),
ExpModel(0.5, 8.),
))
👀 Reading hidden code
19.5 μs

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
291 μs
  • Edit some specific values of interest:

👀 Reading hidden code
3.6 ms
_.comps[1].scale 2.0
_.comps[1].shift 5.0
_.comps[3].shift 8.0
@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.9 s
mod1
👀 Reading hidden code
8.5 μs
  • Edit all scales and shifts:

👀 Reading hidden code
267 μs
_.comps[∗].scale 2.0
0.501
0.501
_.comps[∗].shift 4.99
2.0
8.0
@bind mod2 ColumnInput(mod₀, (
(@o _.comps[∗].scale) => Slider(0..5),
(@o _.comps[∗].shift) => Slider(0..10),
))
👀 Reading hidden code
1.0 s
mod2
👀 Reading hidden code
8.6 μs
  • Show numbers, keys, or any other information using context-optics from AccessorsExtra:

👀 Reading hidden code
246 μs
Loading more cells...