Fork me on GitHub
#clerk
<
2023-06-28
>
seb23110:06:33

Is it possible to insert a hyperlink in a Clerk notebook that automatically opens in a new tab/window?

seb23110:06:42

I have tried ;; [Google](){:target="_blank"} but that doesn't seem to work

seb23111:06:50

Ah figured it out 👍

seb23111:06:52

this worked

seb23111:06:02

(clerk/html "<a href=\"\" target=\"_blank\">Google</a>")

👍 4
seb23115:06:23

I'd like to build an interactive plot using clerk/vl whereby the datasets being on shown on the plot changes based on a slider with predetermined options. At the moment it feels like my biggest hurdle is a lot of our code that processes our datasets is in tablecloth, which I am having trouble accessing through show-sci . We suspect it is because tablecloth doesn't work in cljs. This is the error I'm getting error in render-fn: Could not resolve symbol: tablecloth.api/dataset

mkvlr16:06:47

you don’t tablecloth to run in sci for this, here’s the basic structure that should work regardless of where the data is coming from:

(ns scratch
  (:require [nextjournal.clerk :as clerk]))

^{::clerk/sync true}
(defonce !offset (atom 0))

(comment
  (swap! !offset inc))

(clerk/vl
 {:data {:values [{"a" "A" "b" (+ @!offset 28)} {"a" "B" "b" 100} {"a" "C" "b" 43}
                  {"a" "D" "b" 91} {"a" "E" "b" 81} {"a" "F" "b" 53}
                  {"a" "G" "b" 19} {"a" "H" "b" 87} {"a" "I" "b" 52}]}
  :mark "bar"
  :encoding {"x" {"field" "a" "type" "nominal" "axis" {"labelAngle" 0}}
             "y" {"field" "b" "type" "quantitative"}}
  :embed/opts {:actions false}})

(clerk/with-viewer {:render-fn '(fn [_] [:div [:button.bg-sky-200.p-2.rounded {:on-click #(swap! !offset inc)} "inc"]])} {})

seb23111:06:00

Thanks for that @U5H74UNSF 👍

seb23110:07:33

@U5H74UNSF should these buttons work when "built" an exported as html?

seb23110:07:07

(clerk/build! {:paths    ["notebooks/scratch.clj"]
                 :bundle   true
                 :out-path "."})

seb23110:07:29

Currently it seems to only produce a static version of the notebook with whatever the value of the atom was at build time

mkvlr10:07:44

correct, they won’t work in the static build

seb23112:07:12

@U5H74UNSF can you advise whether it's possible to create a version/build that would have working buttons? Just not sure where to start working towards

mkvlr13:07:16

you can get working buttons if you move the state fully into the frontend and do things with cljs only

mkvlr13:07:56

but that means pushing everything to the browser which might or might not be viable, depending on the size of your dataset

mkvlr13:07:18

also it limits the libraries you can use, certainly tablecloth won’t work in the browser afaik

seb23113:07:31

that's really helpful thank you 👍 Seems like a lot more development for something I use quite casually, so maybe at this point not worth the effort. And as you say it may not even work!

mkvlr13:07:39

yeah, also wouldn’t recommend going down this path for now. We also have something in the works that should make it easy to deploy a clerk notebook with a JVM so the buttons would work in that case. Will keep you posted here when it’s ready to try out.

seb23108:07:04

Sweet, thanks!

Sam Ritchie17:06:00

Everything in emmy-viewers is now compatible with Clerk’s editor mode. Here’s the 3D api, live-editable in the browser: https://emmy-viewers.mentat.org/dev/examples/mathbox/functions/edit

💥 8
🪄 2
jackrusher19:06:50

Nice monkey saddle 😄

🐒 2
Craig Brozefsky18:06:10

I'm running off of a branch, which is a few weeks old, if that helps provide context. I'm not well-versed in how clerk determins that URL, so I may be missing osmething obvious

Craig Brozefsky18:06:25

I'll keep digging...

mkvlr18:06:05

ah yeah, so this is a branch of clerk?

mkvlr18:06:55

try running with bb dev to have clerk build its js

Craig Brozefsky19:06:38

bb dev works for me on that branch

Craig Brozefsky19:06:14

I'll circle back to figuring out how the local resource load vs loading assets from clerk.garden works

Craig Brozefsky19:06:39

Me having issues running from a branch is not a priority for your time, IMO

Craig Brozefsky19:06:16

I got enough material now to figure this out

mkvlr19:06:46

what you’re seeing is expected

Craig Brozefsky19:06:38

I'm assuming that somehow my frontend assets hash changed so I'm looking for one that doesn't exist

mkvlr19:06:15

when you don’t run bb dev (which starts shadow-cljs and compiles it’s own js) clerk computes a hash using https://github.com/nextjournal/clerk/blob/d80187013d7b7b96db3d8b114b8d99f687170668/src/nextjournal/clerk/render/hashing.clj. If you have local changes we won’t have a js bundle for that hash (this will only be built & uploaded on CI on push).

Craig Brozefsky19:06:56

yah, am surprised at the "having local changes part" but I'll get to the bottom of that

mkvlr19:06:00

yeah exactly. If you touch any file that’s part of the hashing you’ll run into this problem.

mkvlr19:06:39

the hashing part is only mean to be used when using clerk as a library, not when developing on clerk

Craig Brozefsky19:06:17

I'm just confused as to why that worked after I made that change, but that was on June 15th, so my memory of details there will just lead me astray 8^)

Craig Brozefsky19:06:37

yah, changed a cljc file... that would do it.

mkvlr19:06:33

also you’d see the effect only after a restart

mkvlr19:06:47

(I think, I always use bb dev)

Craig Brozefsky19:06:59

yah, that's almost assuredly what happened

mkvlr19:06:04

might be nice to show a good error when this happens pointing folks at bb dev

Craig Brozefsky19:06:08

it was the change to remove the print-method on keywords...

mkvlr19:06:32

but can’t think of an easy way now, problem is without a js bundle it’s hard to show a good error 🙃

Craig Brozefsky19:06:24

my first thought goes to building the bundle and then serving it up from the clerk webserver as a resource

mkvlr19:06:25

and checking if the file exists at the url is also not always possible from the JVM thanks to stupid enterprise IT firewalls…

mkvlr19:06:48

that’s what bb dev does

mkvlr19:06:04

but if you started without the :dev alias we can’t build it

Craig Brozefsky19:06:52

yah, so in my use case, I'm using clerk as a dep in my project. We start up a repl or clerk...

mkvlr19:06:18

ok, but you were using a :local/root dep of clerk?

Craig Brozefsky19:06:26

no actually, a git commit

mkvlr19:06:44

ah but a commit of a fork from you

Craig Brozefsky19:06:49

and now I get why that doesn't solve this..... because that's not running from an explictiely built jar, but just a checkout...

mkvlr19:06:51

which doesn’t have clerk’s CI setup

Craig Brozefsky19:06:05

so the bundle wouldn't be there...

Craig Brozefsky19:06:26

and I don't really wanna be yarning in my clojure app 8^)

Craig Brozefsky19:06:46

hmm, maybe I should just use "bb jar" ...

mkvlr19:06:12

there’s an override to fix this

Craig Brozefsky19:06:13

Hmm, all I can think of that is relevant would be the :ssr one for static building

Craig Brozefsky19:06:34

in my case, I am wanting to support dynamic notebook dev

Craig Brozefsky19:06:31

it's a big data collection/analysis tool... want to have clj -M:run clerk start up a clerk server and analysts can existing ntoebooks and create their own

mkvlr19:06:39

clj -M -e "((requiring-resolve 'nextjournal.clerk.render.hashing/dynamic-asset-map))"
{"/js/viewer.js" ""}

mkvlr19:06:52

run this from clerk upstream (e.g. main)

mkvlr19:06:16

then add this to your deps.edn alias

:jvm-opts ["-Dclerk.resource_manifest={\"/js/viewer.js\" \"\"}"]

mkvlr19:06:14

this way you can override the asset map from the computation to a fixed value

Craig Brozefsky19:06:50

that's pretty baller

mkvlr19:06:35

the versions should line up though, so best use e.g. the closest ancestor commit that’s upstream

Craig Brozefsky19:06:38

that resoruce_manifest indirection is handy eh

Craig Brozefsky20:06:14

thanks, this will let me use the clerk notebook sin the workshop I'm doing with analysts next week

🙌 2
mkvlr20:06:07

glad to help

🎉 2
Craig Brozefsky20:06:13

oh and I learned about requiring-resolve

Craig Brozefsky20:06:25

which I swear I end up writing every project...

mkvlr20:06:03

yeah, that’s fairly recent (added in 1.10) and useful

mkvlr20:06:35

we’re thinking about unifying the linking behavior between build! and serve! by dropping consistently dropping the .clj|md|html extensions. The way browsers handle this would make links for the unbundled (= multiple separate html files) only useable when served via a static webserver (with an index.html rewrite). Would that be a problem for folks? The bundled case (single self-contained html with client-side routing) would still work as a normal html that can be opened as is.