|
3 | 3 | {:nextjournal.clerk/visibility {:code :hide :result :hide} |
4 | 4 | :nextjournal.clerk/no-cache true} |
5 | 5 | (:require [nextjournal.clerk :as clerk] |
6 | | - [nextjournal.clerk.window :as window] |
7 | 6 | [nextjournal.clerk.tap :as tap])) |
8 | 7 |
|
9 | | -#_(clerk/window! :my-window (clerk/html [:div.w-8.h-8.bg-green-500])) |
| 8 | +{::clerk/visibility {:code :show}} |
10 | 9 |
|
11 | | -#_(comment |
12 | | - (clerk/close-window! :my-window) |
13 | | - (clerk/close-all-windows!) |
14 | | - (clerk/window! ::clerk/taps) |
15 | | - (tap> (clerk/html [:div.w-8.h-8.bg-green-500])) |
16 | | - (tap> (clerk/plotly {:data [{:x [1 2 3 4]}]})) |
17 | | - (tap/reset-taps!)) |
| 10 | +;; Clerk windows are draggable, resizable and dockable containers that are floating on top of other content. Windows make it easy to show arbitary content, independent of a notebook, while still getting all the benefits of Clerk viewers. This can be nice for debugging. For example you could use it to inspect a data structure in one window and show the same data structure as a graph in a second window. |
| 11 | + |
| 12 | +;; Windows have identity. In order to spawn one, you have to call something like: |
| 13 | + |
| 14 | +(clerk/window! :my-window {:foo (vec (repeat 2 {:baz (range 30) :fooze (range 40)})) :bar (range 20)}) |
| 15 | + |
| 16 | +;; This creates a window with a `:my-window` id. The id makes the window addressable and, as such, allows to update its contents from the REPL. For example, you can call … |
| 17 | + |
| 18 | +(clerk/window! :my-window {:title "A debug window"} (zipmap (range 1000) (map #(* % %) (range 1000)))) |
| 19 | + |
| 20 | +;; … to replace the contens of `:my-window`. The window itself will not be reinstantiated. The example also shows that `window!` takes an optional second `opts` argument that can be used to give it a custom title. |
| 21 | + |
| 22 | +;; Windows have a dedicated close button but you can also use the id to close it from the REPL, e.g. |
| 23 | + |
| 24 | +(clerk/close-window! :my-window) |
| 25 | + |
| 26 | +;; Finally, there's also special `::clerk/taps` window that doesn't require you to set any content. Instead, it will show you a stream of taps (independant of the notebooks you are working in). So, whenever you `tap>` something, the Taps window will show it when it's open: |
| 27 | + |
| 28 | +(comment |
| 29 | + (clerk/window! ::clerk/taps)) |
| 30 | + |
| 31 | +;; Mind that windows live outside notebooks and once you spawn one, it shows until you close it again, even if you reload the page or show a different notebook! |
| 32 | + |
| 33 | +(comment |
| 34 | + (clerk/window! :test {:title "My Super-Duper Window"} (range 100)) |
| 35 | + (clerk/window! :test (clerk/html [:div.w-8.h-8.bg-green-500])) |
| 36 | + (clerk/close-window! :test) |
| 37 | + (clerk/close-all-windows!) |
| 38 | + (clerk/window! ::clerk/taps) |
| 39 | + (tap> (clerk/html [:div.w-8.h-8.bg-green-500])) |
| 40 | + (tap> (clerk/vl {:description "A simple bar chart with embedded data." |
| 41 | + :data {:values [{:a "A" :b 28} {:a "B" :b 55} {:a "C" :b 43} |
| 42 | + {:a "D" :b 91} {:a "E" :b 81} {:a "F" :b 53} |
| 43 | + {:a "G" :b 19} {:a "H" :b 87} {:a "I" :b 52}]} |
| 44 | + :mark "bar" |
| 45 | + :encoding {:x {:field "a" :type "nominal" :axis {:labelAngle 0}} |
| 46 | + :y {:field "b" :type "quantitative"}}})) |
| 47 | + (tap> 1) |
| 48 | + (tap/reset-taps!)) |
0 commit comments