This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-28
Channels
- # announcements (5)
- # babashka (7)
- # beginners (46)
- # biff (28)
- # calva (7)
- # cider (3)
- # clerk (82)
- # clj-commons (9)
- # clj-kondo (7)
- # clojure (37)
- # clojure-dev (16)
- # clojure-europe (18)
- # clojure-norway (7)
- # clojurescript (8)
- # clojureverse-ops (3)
- # cursive (5)
- # datomic (4)
- # emacs (20)
- # exercism (2)
- # lsp (58)
- # off-topic (32)
- # polylith (11)
- # reitit (7)
- # tools-build (7)
- # xtdb (4)
Is it possible to insert a hyperlink in a Clerk notebook that automatically opens in a new tab/window?
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
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"]])} {})
Thanks for that @U5H74UNSF 👍
@U5H74UNSF should these buttons work when "built" an exported as html?
Currently it seems to only produce a static version of the notebook with whatever the value of the atom was at build time
@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
you can get working buttons if you move the state fully into the frontend and do things with cljs only
but that means pushing everything to the browser which might or might not be viable, depending on the size of your dataset
also it limits the libraries you can use, certainly tablecloth won’t work in the browser afaik
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!
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.
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
My clerk has started failing, I think because this asset is no longer present: https://storage.clerk.garden/nextjournal/clerk-assets@3FKf7oB1VkjwSgcPkPQLRzUDZhq7/viewer.js?immutable=true
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
I'll keep digging...
thank 8^)
bb dev works for me on that branch
I'll circle back to figuring out how the local resource load vs loading assets from clerk.garden works
Me having issues running from a branch is not a priority for your time, IMO
I got enough material now to figure this out
I'm assuming that somehow my frontend assets hash changed so I'm looking for one that doesn't exist
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).
yah, am surprised at the "having local changes part" but I'll get to the bottom of that
yeah exactly. If you touch any file that’s part of the hashing you’ll run into this problem.
and found it...
the hashing part is only mean to be used when using clerk as a library, not when developing on clerk
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^)
yah, changed a cljc file... that would do it.
yah, that's almost assuredly what happened
it was the change to remove the print-method on keywords...
but can’t think of an easy way now, problem is without a js bundle it’s hard to show a good error 🙃
my first thought goes to building the bundle and then serving it up from the clerk webserver as a resource
and checking if the file exists at the url is also not always possible from the JVM thanks to stupid enterprise IT firewalls…
yah, so in my use case, I'm using clerk as a dep in my project. We start up a repl or clerk...
no actually, a git commit
and now I get why that doesn't solve this..... because that's not running from an explictiely built jar, but just a checkout...
so the bundle wouldn't be there...
and I don't really wanna be yarning in my clojure app 8^)
hmm, maybe I should just use "bb jar" ...
Hmm, all I can think of that is relevant would be the :ssr one for static building
in my case, I am wanting to support dynamic notebook dev
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
clj -M -e "((requiring-resolve 'nextjournal.clerk.render.hashing/dynamic-asset-map))"
{"/js/viewer.js" ""}
then add this to your deps.edn
alias
:jvm-opts ["-Dclerk.resource_manifest={\"/js/viewer.js\" \"\"}"]
oh, sweet
that's pretty baller
the versions should line up though, so best use e.g. the closest ancestor commit that’s upstream
that resoruce_manifest indirection is handy eh
thanks, this will let me use the clerk notebook sin the workshop I'm doing with analysts next week
oh and I learned about requiring-resolve
which I swear I end up writing every project...
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.