Skip to content

Commit

Permalink
Add missing deps + data for How Clerk Works, add tablecloth sample
Browse files Browse the repository at this point in the history
  • Loading branch information
mk committed Oct 8, 2021
1 parent 4195e80 commit c5358a6
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

This is a preview of Clerk before its open source release. See the
[Clerk README](https://nextjournal.com/mk/clerk-preview) for more information.

To play with this, eval forms in [dev/user.clj](dev/user.clj).
Binary file added datasets/chinook.db
Binary file not shown.
151 changes: 151 additions & 0 deletions datasets/iris.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"sepal.length","sepal.width","petal.length","petal.width","variety"
5.1,3.5,1.4,.2,"Setosa"
4.9,3,1.4,.2,"Setosa"
4.7,3.2,1.3,.2,"Setosa"
4.6,3.1,1.5,.2,"Setosa"
5,3.6,1.4,.2,"Setosa"
5.4,3.9,1.7,.4,"Setosa"
4.6,3.4,1.4,.3,"Setosa"
5,3.4,1.5,.2,"Setosa"
4.4,2.9,1.4,.2,"Setosa"
4.9,3.1,1.5,.1,"Setosa"
5.4,3.7,1.5,.2,"Setosa"
4.8,3.4,1.6,.2,"Setosa"
4.8,3,1.4,.1,"Setosa"
4.3,3,1.1,.1,"Setosa"
5.8,4,1.2,.2,"Setosa"
5.7,4.4,1.5,.4,"Setosa"
5.4,3.9,1.3,.4,"Setosa"
5.1,3.5,1.4,.3,"Setosa"
5.7,3.8,1.7,.3,"Setosa"
5.1,3.8,1.5,.3,"Setosa"
5.4,3.4,1.7,.2,"Setosa"
5.1,3.7,1.5,.4,"Setosa"
4.6,3.6,1,.2,"Setosa"
5.1,3.3,1.7,.5,"Setosa"
4.8,3.4,1.9,.2,"Setosa"
5,3,1.6,.2,"Setosa"
5,3.4,1.6,.4,"Setosa"
5.2,3.5,1.5,.2,"Setosa"
5.2,3.4,1.4,.2,"Setosa"
4.7,3.2,1.6,.2,"Setosa"
4.8,3.1,1.6,.2,"Setosa"
5.4,3.4,1.5,.4,"Setosa"
5.2,4.1,1.5,.1,"Setosa"
5.5,4.2,1.4,.2,"Setosa"
4.9,3.1,1.5,.2,"Setosa"
5,3.2,1.2,.2,"Setosa"
5.5,3.5,1.3,.2,"Setosa"
4.9,3.6,1.4,.1,"Setosa"
4.4,3,1.3,.2,"Setosa"
5.1,3.4,1.5,.2,"Setosa"
5,3.5,1.3,.3,"Setosa"
4.5,2.3,1.3,.3,"Setosa"
4.4,3.2,1.3,.2,"Setosa"
5,3.5,1.6,.6,"Setosa"
5.1,3.8,1.9,.4,"Setosa"
4.8,3,1.4,.3,"Setosa"
5.1,3.8,1.6,.2,"Setosa"
4.6,3.2,1.4,.2,"Setosa"
5.3,3.7,1.5,.2,"Setosa"
5,3.3,1.4,.2,"Setosa"
7,3.2,4.7,1.4,"Versicolor"
6.4,3.2,4.5,1.5,"Versicolor"
6.9,3.1,4.9,1.5,"Versicolor"
5.5,2.3,4,1.3,"Versicolor"
6.5,2.8,4.6,1.5,"Versicolor"
5.7,2.8,4.5,1.3,"Versicolor"
6.3,3.3,4.7,1.6,"Versicolor"
4.9,2.4,3.3,1,"Versicolor"
6.6,2.9,4.6,1.3,"Versicolor"
5.2,2.7,3.9,1.4,"Versicolor"
5,2,3.5,1,"Versicolor"
5.9,3,4.2,1.5,"Versicolor"
6,2.2,4,1,"Versicolor"
6.1,2.9,4.7,1.4,"Versicolor"
5.6,2.9,3.6,1.3,"Versicolor"
6.7,3.1,4.4,1.4,"Versicolor"
5.6,3,4.5,1.5,"Versicolor"
5.8,2.7,4.1,1,"Versicolor"
6.2,2.2,4.5,1.5,"Versicolor"
5.6,2.5,3.9,1.1,"Versicolor"
5.9,3.2,4.8,1.8,"Versicolor"
6.1,2.8,4,1.3,"Versicolor"
6.3,2.5,4.9,1.5,"Versicolor"
6.1,2.8,4.7,1.2,"Versicolor"
6.4,2.9,4.3,1.3,"Versicolor"
6.6,3,4.4,1.4,"Versicolor"
6.8,2.8,4.8,1.4,"Versicolor"
6.7,3,5,1.7,"Versicolor"
6,2.9,4.5,1.5,"Versicolor"
5.7,2.6,3.5,1,"Versicolor"
5.5,2.4,3.8,1.1,"Versicolor"
5.5,2.4,3.7,1,"Versicolor"
5.8,2.7,3.9,1.2,"Versicolor"
6,2.7,5.1,1.6,"Versicolor"
5.4,3,4.5,1.5,"Versicolor"
6,3.4,4.5,1.6,"Versicolor"
6.7,3.1,4.7,1.5,"Versicolor"
6.3,2.3,4.4,1.3,"Versicolor"
5.6,3,4.1,1.3,"Versicolor"
5.5,2.5,4,1.3,"Versicolor"
5.5,2.6,4.4,1.2,"Versicolor"
6.1,3,4.6,1.4,"Versicolor"
5.8,2.6,4,1.2,"Versicolor"
5,2.3,3.3,1,"Versicolor"
5.6,2.7,4.2,1.3,"Versicolor"
5.7,3,4.2,1.2,"Versicolor"
5.7,2.9,4.2,1.3,"Versicolor"
6.2,2.9,4.3,1.3,"Versicolor"
5.1,2.5,3,1.1,"Versicolor"
5.7,2.8,4.1,1.3,"Versicolor"
6.3,3.3,6,2.5,"Virginica"
5.8,2.7,5.1,1.9,"Virginica"
7.1,3,5.9,2.1,"Virginica"
6.3,2.9,5.6,1.8,"Virginica"
6.5,3,5.8,2.2,"Virginica"
7.6,3,6.6,2.1,"Virginica"
4.9,2.5,4.5,1.7,"Virginica"
7.3,2.9,6.3,1.8,"Virginica"
6.7,2.5,5.8,1.8,"Virginica"
7.2,3.6,6.1,2.5,"Virginica"
6.5,3.2,5.1,2,"Virginica"
6.4,2.7,5.3,1.9,"Virginica"
6.8,3,5.5,2.1,"Virginica"
5.7,2.5,5,2,"Virginica"
5.8,2.8,5.1,2.4,"Virginica"
6.4,3.2,5.3,2.3,"Virginica"
6.5,3,5.5,1.8,"Virginica"
7.7,3.8,6.7,2.2,"Virginica"
7.7,2.6,6.9,2.3,"Virginica"
6,2.2,5,1.5,"Virginica"
6.9,3.2,5.7,2.3,"Virginica"
5.6,2.8,4.9,2,"Virginica"
7.7,2.8,6.7,2,"Virginica"
6.3,2.7,4.9,1.8,"Virginica"
6.7,3.3,5.7,2.1,"Virginica"
7.2,3.2,6,1.8,"Virginica"
6.2,2.8,4.8,1.8,"Virginica"
6.1,3,4.9,1.8,"Virginica"
6.4,2.8,5.6,2.1,"Virginica"
7.2,3,5.8,1.6,"Virginica"
7.4,2.8,6.1,1.9,"Virginica"
7.9,3.8,6.4,2,"Virginica"
6.4,2.8,5.6,2.2,"Virginica"
6.3,2.8,5.1,1.5,"Virginica"
6.1,2.6,5.6,1.4,"Virginica"
7.7,3,6.1,2.3,"Virginica"
6.3,3.4,5.6,2.4,"Virginica"
6.4,3.1,5.5,1.8,"Virginica"
6,3,4.8,1.8,"Virginica"
6.9,3.1,5.4,2.1,"Virginica"
6.7,3.1,5.6,2.4,"Virginica"
6.9,3.1,5.1,2.3,"Virginica"
5.8,2.7,5.1,1.9,"Virginica"
6.8,3.2,5.9,2.3,"Virginica"
6.7,3.3,5.7,2.5,"Virginica"
6.7,3,5.2,2.3,"Virginica"
6.3,2.5,5,1.9,"Virginica"
6.5,3,5.2,2,"Virginica"
6.2,3.4,5.4,2.3,"Virginica"
5.9,3,5.1,1.8,"Virginica"
8 changes: 6 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{:paths ["dev"]
:deps {io.github.nextjournal/clerk {:mvn/version "0.1.164"}
org.clojure/data.csv {:mvn/version "1.0.0"}}}
:deps {io.github.nextjournal/clerk {:mvn/version "0.1.164"}

com.github.seancorfield/next.jdbc {:mvn/version "1.2.659"}
scicloj/tablecloth {:mvn/version "6.012"}
org.clojure/data.csv {:mvn/version "1.0.0"}
org.xerial/sqlite-jdbc {:mvn/version "3.34.0"}}}
4 changes: 3 additions & 1 deletion dev/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(comment
;; Optionally start a file-watcher to automatically refresh notebooks when saved
(def filewatcher
(beholder/watch #(clerk/file-event %) "notebooks"))
(beholder/watch #(clerk/file-event %) "notebooks" "src"))

(beholder/stop filewatcher)

Expand All @@ -20,6 +20,8 @@
(clerk/show! "notebooks/viewer_api.clj")
(clerk/show! "notebooks/rule_30.clj")
(clerk/show! "notebooks/elements.clj")
(clerk/show! "notebooks/pagination.clj")
(clerk/show! "notebooks/how_clerk_works.clj")

(clerk/show! "notebooks/viewers/html.clj")
(clerk/show! "notebooks/viewers/markdown.clj")
Expand Down
2 changes: 1 addition & 1 deletion notebooks/how_clerk_works.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
;; For side effectful functions that should be cached, like a database query, you can add a value like this `#inst` to control when evaluation should happen.
(def query-results
(let [_run-at #inst "2021-05-20T08:28:29.445-00:00"
ds (next.jdbc/get-datasource {:dbtype "sqlite" :dbname "chinook.db"})]
ds (next.jdbc/get-datasource {:dbtype "sqlite" :dbname "datasets/chinook.db"})]
(with-open [conn (next.jdbc/get-connection ds)]
(nextjournal.clerk/table (next.jdbc/execute! conn ["SELECT AlbumId, Bytes, Name, TrackID, UnitPrice FROM tracks"])))))

Expand Down
27 changes: 27 additions & 0 deletions notebooks/tablecloth.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
;; # Tablecloth Sample
;; Adapted from [playground.clj](https://github.com/scicloj/tablecloth/blob/9ed00539e5f0ddfde7e51afa111d573bef620042/playground.clj)
(ns tablecloth
(:require [tablecloth.api :as tc]
[nextjournal.clerk :as clerk]))

(defn cartesian-product
[xxs]
(if (seq xxs)
(for [n (cartesian-product (rest xxs))
x (first xxs)]
(conj n x))
'(nil)))

(defn expand-grid
[in]
(-> (map (partial zipmap (keys in))
(cartesian-product (vals in)))
(tc/dataset)))

(def input {:height (range 60 81 5)
:weight (range 100 301 50)
:sex [:Male :Female]})

(expand-grid input)

#_(clerk/show! "notebooks/tablecloth.clj")
2 changes: 1 addition & 1 deletion notebooks/viewers/table.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[nextjournal.clerk :as clerk]))


(clerk/table (csv/read-csv (slurp "https://gist.githubusercontent.com/netj/8836201/raw/6f9306ad21398ea43cba4f7d537619d0e07d5ae3/iris.csv")))
(clerk/table (csv/read-csv (slurp "datasets/iris.csv")))
Empty file added src/.gitkeep
Empty file.

0 comments on commit c5358a6

Please sign in to comment.