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 4 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
👀 Reading hidden code
embed_display(@htl("""
<script id=$(rand(UInt))>console.log(1233)</script>
$(embed_display([1,2]))
"""))
498 ms

Number 4 – final attempt

👀 Reading hidden code
md"""
## Number 4 -- final attempt
"""
191 μs
👀 Reading hidden code
begin
struct EmbeddableDisplay4
x
script_id
end
function Base.show(io::IO, m::MIME"text/html", e::EmbeddableDisplay4)
body, mime = PlutoRunner.format_output_default(e.x, io)
write(io, """
<pluto-display></pluto-display>
<script id=$(e.script_id)>
const body = $(PlutoRunner.publish_to_js(body, e.script_id))
const mime = "$(string(mime))"
const create_new = this == null || this._mime !== mime
// console.log(mime, this?._mime, this?._body, body, this?._body === body, create_new)


const display = create_new ? currentScript.previousElementSibling : this //document.createElement("pluto-display") : this
1.7 ms
Error message

UndefVarError: Layout not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. hbox_even(::Main.workspace#6.EmbeddableDisplay4, ::Vararg{Main.workspace#6.EmbeddableDisplay4})
    hbox_even(elements...) = Layout.flex(equal_container.(elements)...)
  2. Show more...
asdf22 = demo2(embed_display4);
👀 Reading hidden code
---
Error message

Another cell defining asdf22 contains errors.

asdf22
👀 Reading hidden code
---
aasdff = rand(50)
👀 Reading hidden code
14.5 μs
Error message

Failed to show value:

MethodError: no method matching publish_to_js(::Dict{Symbol, Any}, ::String)

Closest candidates are:

publish_to_js(::Any) at ~/.julia/packages/Pluto/6smog/src/runner/PlutoRunner/src/js/published_to_js.jl:39

Stack trace

Here is what happened, the most recent locations are first:

  1. show(io::IOContext{IOBuffer}, m::MIME{Symbol("text/html")}, e::Main.workspace#6.EmbeddableDisplay4)
    	    body, mime = PlutoRunner.format_output_default(e.x, io)				write(io, """			<pluto-display></pluto-display>	<script id=$(e.script_id)>
embed_display4(aasdff) |> embed_display4 |> embed_display4 |> embed_display4
👀 Reading hidden code
27.5 μs
embed_display4 (generic function with 1 method)

embed_display4(x) = EmbeddableDisplay4(x, rand('a':'z',16) |> join)
👀 Reading hidden code
468 μs

Number 3 – preact

👀 Reading hidden code
185 μs
Error message

UndefVarError: Layout not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. hbox_even(::Main.workspace#6.EmbeddableDisplay3, ::Vararg{Main.workspace#6.EmbeddableDisplay3})
    hbox_even(elements...) = Layout.flex(equal_container.(elements)...)
  2. Show more...
demo23 = demo2(embed_display3);
👀 Reading hidden code
---
Error message

Failed to show value:

MethodError: no method matching publish_to_js(::Dict{Symbol, Any}, ::String)

Closest candidates are:

publish_to_js(::Any) at ~/.julia/packages/Pluto/6smog/src/runner/PlutoRunner/src/js/published_to_js.jl:39

Stack trace

Here is what happened, the most recent locations are first:

  1. show(io::IOContext{IOBuffer}, m::MIME{Symbol("text/html")}, e::Main.workspace#6.EmbeddableDisplay3)
    	    body, mime = PlutoRunner.format_output_default(e.x, io)				write(io, """	<script type=module id=$(e.script_id)>			
demo1(embed_display3) |> embed_display3 |> embed_display3 |> embed_display3
👀 Reading hidden code
27.0 ms
Error message

Another cell defining demo23 contains errors.

lkjasdfklj; demo23
👀 Reading hidden code
---
1233
lkjasdfklj = 1233
👀 Reading hidden code
14.6 μs
begin
struct EmbeddableDisplay3
x
script_id
end
function Base.show(io::IO, m::MIME"text/html", e::EmbeddableDisplay3)
body, mime = PlutoRunner.format_output_default(e.x, io)
write(io, """
<script type=module id=$(e.script_id)>
const { html, render, Component, useEffect, useLayoutEffect, useState, useRef, useMemo, createContext, useContext, } = await import("../imports/Preact.js")
const { OutputBody } = await import("./CellOutput.js")

const node = this ?? document.createElement("span")
const new_state = {
body: $(PlutoRunner.publish_to_js(body, e.script_id)),
mime: "$(string(mime))",
}
if(this == null){
const App = () => {

const [state, set_state] = useState(new_state)
node.set_app_state = set_state
const run_count = useRef(0)
const persist_js_state = run_count.current > 0
run_count.current++;

return html`<\${OutputBody} mime=\${state.mime} body=\${state.body} persist_js_state=\${persist_js_state} />`
}

render(html`<\${App}/>`, node);
} else {
node.set_app_state(new_state)
}
return node
</script>
""")
end
end
👀 Reading hidden code
1.6 ms
Error message

UndefVarError: Layout not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. hbox_even(::Main.workspace#6.EmbeddableDisplay3, ::Vararg{Main.workspace#6.EmbeddableDisplay3})
    hbox_even(elements...) = Layout.flex(equal_container.(elements)...)
  2. Show more...
Everything is going to be okay!
k3 = demo2(embed_display3)
👀 Reading hidden code
---
Error message

Another cell defining k3 contains errors.

Everything is going to be okay!
zzz3; k3
👀 Reading hidden code
---
Error message

Another cell defining k3 contains errors.

k3 |> embed_display3 |> embed_display3
👀 Reading hidden code
---
123
zzz3 = 123
👀 Reading hidden code
10.2 μs
embed_display3 (generic function with 1 method)

embed_display3(x) = EmbeddableDisplay3(x, rand('a':'z',16) |> join)
👀 Reading hidden code
437 μs
embed_display2 (generic function with 1 method)

embed_display2(x) = EmbeddableDisplay2(x, rand('a':'z',16) |> join)
👀 Reading hidden code
413 μs
begin
struct EmbeddableDisplay2
x
script_id
end
function Base.show(io::IO, m::MIME"text/html", e::EmbeddableDisplay2)
body, mime = PlutoRunner.format_output_default(e.x, io)
write(io, """
<script id=$(e.script_id)>
const body = $(PlutoRunner.publish_to_js(body, e.script_id))
const mime = "$(string(mime))"
console.log(body)
const create_new = this == null || this._mime !== mime
console.log(mime, this?._mime, this?._body, body, this?._body === body, create_new)

const display = create_new ? document.createElement("pluto-display") : this
display.body = body
//display.body = {...body}
//display.body = body
display._body = body
if(create_new) {
display.mime = mime
display._mime = mime
}
return display
</script>
""")
end
end
👀 Reading hidden code
4.2 ms
121
f = 121
👀 Reading hidden code
11.8 μs
dd = [[1,2],3]
👀 Reading hidden code
24.2 ms
Error message

Failed to show value:

MethodError: no method matching publish_to_js(::Dict{Symbol, Any}, ::String)

Closest candidates are:

publish_to_js(::Any) at ~/.julia/packages/Pluto/6smog/src/runner/PlutoRunner/src/js/published_to_js.jl:39

Stack trace

Here is what happened, the most recent locations are first:

  1. show(io::IOContext{IOBuffer}, m::MIME{Symbol("text/html")}, e::Main.workspace#6.EmbeddableDisplay2)
    	    body, mime = PlutoRunner.format_output_default(e.x, io)				write(io, """	<script id=$(e.script_id)>			
Don't panic!
k = demo1(embed_display2)
👀 Reading hidden code
14.9 ms
Error message

Failed to show value:

MethodError: no method matching publish_to_js(::Dict{Symbol, Any}, ::String)

Closest candidates are:

publish_to_js(::Any) at ~/.julia/packages/Pluto/6smog/src/runner/PlutoRunner/src/js/published_to_js.jl:39

Stack trace

Here is what happened, the most recent locations are first:

  1. show(io::IOContext{IOBuffer}, m::MIME{Symbol("text/html")}, e::Main.workspace#6.EmbeddableDisplay2)
    	    body, mime = PlutoRunner.format_output_default(e.x, io)				write(io, """	<script id=$(e.script_id)>			
Be patient :)
zzz; k
👀 Reading hidden code
10.9 μs
123
zzz = 123
👀 Reading hidden code
11.2 μs
demo1 (generic function with 1 method)
demo1(p) = p(rand(50))
👀 Reading hidden code
368 μs
Error message

UndefVarError: Layout not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. hbox_even(::Main.workspace#6.EmbeddableDisplay2, ::Vararg{Main.workspace#6.EmbeddableDisplay2})
    hbox_even(elements...) = Layout.flex(equal_container.(elements)...)
  2. Show more...
r = demo2(embed_display2)
👀 Reading hidden code
---
demo2 (generic function with 1 method)
demo2(p) = let
x = rand(f)
hbox_even(p(x), p(plot(x)))
end
👀 Reading hidden code
512 μs
embed_display([1,2])
👀 Reading hidden code
16.7 μs
Error message

UndefVarError: Layout not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. hbox_even(::PlutoRunner.EmbeddableDisplay, ::Vararg{PlutoRunner.EmbeddableDisplay})
    hbox_even(elements...) = Layout.flex(equal_container.(elements)...)
  2. Show more...
let
x = rand(f)
hbox_even(embed_display(x), embed_display(plot(x)))
end
👀 Reading hidden code
---
showhtml (generic function with 1 method)
showhtml(r) = repr(MIME"text/html"(), r) |> Text
👀 Reading hidden code
441 μs
Error message

Failed to show value:

MethodError: no method matching publish_to_js(::Dict{Symbol, Any}, ::String)

Closest candidates are:

publish_to_js(::Any) at ~/.julia/packages/Pluto/6smog/src/runner/PlutoRunner/src/js/published_to_js.jl:39

Stack trace

Here is what happened, the most recent locations are first:

  1. show(io::IOContext{IOBuffer}, m::MIME{Symbol("text/html")}, e::Main.workspace#6.EmbeddableDisplay2)
    	    body, mime = PlutoRunner.format_output_default(e.x, io)				write(io, """	<script id=$(e.script_id)>			
C'est la vie !
p([1,2])
👀 Reading hidden code
17.2 μs
PlutoRunner.format_output_default(rand(10))
👀 Reading hidden code
3.4 ms

👀 Reading hidden code
68.7 μs
@bind z Slider(1:100)
👀 Reading hidden code
156 ms
data = rand(z)
👀 Reading hidden code
14.8 μs

👀 Reading hidden code
67.6 μs
Error message

Another cell defining Layout contains errors.

Layout.flex(p(data), p(data .* 10))
👀 Reading hidden code
---
embed_display2 (generic function with 1 method)
p = embed_display2
👀 Reading hidden code
11.7 μs
using PlutoUI
👀 Reading hidden code
204 ms
equal_container (generic function with 1 method)
equal_container(x) = Layout.Div(x, Dict(
"flex" => "1 1 0px",
"overflow-x" => "auto",
))
👀 Reading hidden code
459 μs
hbox_even (generic function with 1 method)
hbox_even(elements...) = Layout.flex(equal_container.(elements)...)
👀 Reading hidden code
492 μs
Error message

Failed to show value:

MethodError: no method matching publish_to_js(::Dict{Symbol, Any}, ::String)

Closest candidates are:

publish_to_js(::Any) at ~/.julia/packages/Pluto/6smog/src/runner/PlutoRunner/src/js/published_to_js.jl:39

Stack trace

Here is what happened, the most recent locations are first:

  1. show(io::IOContext{IOBuffer}, m::MIME{Symbol("text/html")}, e::Main.workspace#6.EmbeddableDisplay2)
    	    body, mime = PlutoRunner.format_output_default(e.x, io)				write(io, """	<script id=$(e.script_id)>			
p(rand(20))
👀 Reading hidden code
18.3 μs
rand(20)
👀 Reading hidden code
14.5 μs
Error message

LoadError: ArgumentError: Package Hyperscript not found in current path:

- Run `import Pkg; Pkg.add("Hyperscript")` to install the Hyperscript package.


in expression starting at /tmp/jl_BSPXgU:8

Stack trace

Here is what happened, the most recent locations are first:

  1. require(into::Module, mod::Symbol)
  2. include
  3. include(x::String)
            Expr(:toplevel,             :(eval(x) = $(Expr(:core, :eval))($name, x)),             :(include(x) = $(Expr(:top, :include))($name, x)),             :(include(mapexpr::Function, x) = $(Expr(:top, :include))(mapexpr, $name, x)),             :(include($path))))
  4. Show more...
Layout = ingredients(download("https://fonsp-disorganised-mess.netlify.app/Layout.jl"))
👀 Reading hidden code
---
ingredients (generic function with 1 method)
👀 Reading hidden code
1.1 ms
Error message

UndefVarError: publish_object not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. getproperty
    from Base.jl:35
  2. 	# id = "asdf"	id = PlutoRunner.publish_object([1,2123,12,312323])	
let
# id = "asdf"
id = PlutoRunner.publish_object([1,2123,12,312323])
@htl("""
<script>
const cell = currentScript.closest("pluto-cell")
console.log(await cell.get_published_object($(JSON.json(id))))
</script>
""")
end
👀 Reading hidden code
---
Error message

UndefVarError: publish_object not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. getproperty
    from Base.jl:35
  2. 	# id = "asdf"	id = PlutoRunner.publish_object([1,2,2,13,2,123,12,312323])	
let
# id = "asdf"
id = PlutoRunner.publish_object([1,2,2,13,2,123,12,312323])
@htl("""
<script>
const cell = currentScript.closest("pluto-cell")
console.log(await cell.get_published_object($(JSON.json(id))))
</script>
""")
end
👀 Reading hidden code
---
["asdf", "asdf"]
👀 Reading hidden code
19.1 μs
"asdf"
"asdf"
👀 Reading hidden code
16.8 μs

asdf

asdf

md"""

> asdf

asdf
"""
👀 Reading hidden code
226 μs

hello

asdf
mm = md"""
hello

```
asdf
```

"""
👀 Reading hidden code
3.1 ms
[mm, mm]
👀 Reading hidden code
11.9 μs

Wow code

is difficult to typeset!

md"""
# Wow `code`

is `difficult` to **`typeset`**!
"""
👀 Reading hidden code
299 μs
alksjdlkjasdf
html"""
<div>

<pluto-display></pluto-display>

<script>

const display = currentScript.parentElement.querySelector("pluto-display")

display.mime = "text/plain"
display.body = "alksjdlkjasdf"

const handle = setInterval(() => {
//display.body = Math.random()
}, 1000)

invalidation.then(() => clearInterval(handle))

</script>

</div>


"""
👀 Reading hidden code
131 μs
asdfasdf
html"""
<div>

asdfasdf

<pluto-display></pluto-display>

<script>

const display = currentScript.parentElement.querySelector("pluto-display")


const body = JSON.parse(atob("eyJwcmVmaXgiOiJBbnkiLCJlbGVtZW50cyI6W1sxLFsiOCIsInRleHQvcGxhaW4iXV0sWzIsWyIyIiwidGV4dC9wbGFpbiJdXSxbMyxbIjMiLCJ0ZXh0L3BsYWluIl1dLFs0LFt7InByZWZpeCI6IkludDY0IiwiZWxlbWVudHMiOltbMSxbIjQiLCJ0ZXh0L3BsYWluIl1dLFsyLFsiNSIsInRleHQvcGxhaW4iXV1dLCJ0eXBlIjoiQXJyYXkiLCJwcmVmaXhfc2hvcnQiOiIiLCJvYmplY3RpZCI6IjdkY2U4MDdkNWM3ZTg4M2QifSwiYXBwbGljYXRpb24vdm5kLnBsdXRvLnRyZWUrb2JqZWN0Il1dXSwidHlwZSI6IkFycmF5IiwicHJlZml4X3Nob3J0IjoiIiwib2JqZWN0aWQiOiJkZjRhYjNkYzdjNzJlZTJkIn0="))


display.body = body
display.mime = "application/vnd.pluto.tree+object"

</script>

</div>


"""
👀 Reading hidden code
122 μs
using JSON
👀 Reading hidden code
125 μs
using HypertextLiteral
👀 Reading hidden code
126 μs
bx = @bind x html"<input type=range>"
👀 Reading hidden code
41.1 ms
missing
x
👀 Reading hidden code
8.4 μs
Error message

UndefVarError: pluto_display1 not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. pluto_display1(pluto_display1(bx))
pluto_display1(pluto_display1(bx))
👀 Reading hidden code
---
Error message

UndefVarError: pluto_display1 not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. pluto_display1([1,2])
Silly computer!
pluto_display1([1,2])
👀 Reading hidden code
---
Error message

UndefVarError: pluto_display1 not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. md"""# asdf
Don't panic!
md"""
# asdf

$(pluto_display1([8,9]))

WOW
"""
👀 Reading hidden code
---
Error message

UndefVarError: pluto_display1 not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. [	pluto_display1([1,2]),
[
pluto_display1([1,2]),
123,
"asdf",
md"""
# asdf
$(pluto_display1([8,9]))
1
WOW
""",
p
]
👀 Reading hidden code
---
Error message

Failed to show value:

MethodError: no method matching publish_to_js(::Dict{Symbol, Any}, ::String)

Closest candidates are:

publish_to_js(::Any) at ~/.julia/packages/Pluto/6smog/src/runner/PlutoRunner/src/js/published_to_js.jl:39

Stack trace

Here is what happened, the most recent locations are first:

  1. show(io::IOContext{IOBuffer}, m::MIME{Symbol("text/html")}, e::Main.workspace#6.EmbeddableDisplay2)
    	    body, mime = PlutoRunner.format_output_default(e.x, io)				write(io, """	<script id=$(e.script_id)>			
[1,2] |> p |> p |> p
👀 Reading hidden code
16.9 ms
pluto_display2 (generic function with 1 method)
function pluto_display2(x)
body, mime = PlutoRunner.format_output_default(x)
HTML("""
<pluto-display></pluto-display>

<script>

const display = currentScript.previousElementSibling

display.body = $(PlutoRunner.publish_to_js(body))
display.mime = "$(string(mime))"

</script>

""")
end
👀 Reading hidden code
732 μs
[
pluto_display2([1,2]),
123,
"asdf",
md"""
# asdf
$(pluto_display2([8,9]))
WOW
""",
coolplot
]
👀 Reading hidden code
Deprecated, use `AbstractPlutoDingetjes.Display.published_to_js(x)` instead of `PlutoRunner.publish_to_js(x)`.
Deprecated, use `AbstractPlutoDingetjes.Display.published_to_js(x)` instead of `PlutoRunner.publish_to_js(x)`.
486 ms
using Plots
👀 Reading hidden code
61.6 s
coolplot = plot(1:10, 1:10)
👀 Reading hidden code
55.7 ms

👀 Reading hidden code
67.5 μs
pluto_display2([1,2,3])
👀 Reading hidden code
Deprecated, use `AbstractPlutoDingetjes.Display.published_to_js(x)` instead of `PlutoRunner.publish_to_js(x)`.
592 μs

👀 Reading hidden code
67.2 μs
JSON.lower(m::MIME) = JSON.lower(string(m))
👀 Reading hidden code
400 μs
Error message

UndefVarError: pluto_display not defined

Stack trace

Here is what happened, the most recent locations are first:

  1. md"""
md"""

# Hello!

$(pluto_display([1,2,3]))

cool

"""
👀 Reading hidden code
---
hello!!
html"""
<pluto-display mime="text/plain" body="hello!!" ></pluto-display>
"""
👀 Reading hidden code
120 μs
[8,2,3,[4,5]]
👀 Reading hidden code
23.5 ms