notespace icon indicating copy to clipboard operation
notespace copied to clipboard

pink-gorilla integration

Open awb99 opened this issue 5 years ago • 16 comments

Hi Daniel!

You made a fantastic library here! I would like to integrate this to pink gorilla! Essentially each notespace file is a notebook whose input cells are set by the sourcecode in the IDE.

It should be possible to link this two projects.

Essentially a namespace gets shown in the notebook as a notebook. And cool thing is we could write notebooks back to .clj note files also. So development could happen partially in notebook and partially in ide.

Can you help in refactoring your library so that it essentially would just emit events on a core async channel ?

´´´ {:switch-ns demo1} {:code "(+ 1 1)" :id 1} {:refresh :id 1} {:switch-ns demo2} ´´´ Regards

awb99 avatar Mar 23 '20 01:03 awb99

Hi Daniel!

I added a prototype of the Pinkie Renderer which should be able to be plugged into Pink-Gorilla Notebook very easily.

git clone https://github.com/pink-gorilla/gorilla-notebook.git
cd gorilla-notebook
git checkout pinkie
lein build-shadow-pinkie
#lein run-pinkie

Open gorilla-notebook project in your favorite ide and start the clojure repl (I use visual studio code with calva), and then load the namespace pinkie.app (it is in src/pinkie/pinkie/app.clj)

Eval the following expressions line by line.

 (start-server!)   ; this opens the web browser
  (pinkie.server/start-heartbeats!)  ; for my dev machine without heartbeats websocket drops.

 (code-add 1 "(- 100 5)")
  (result-set 1 95)

  (code-add 2 "[1 2 {:a 1 :b 2 :c 3}]")
  (result-set 2 [1 2 {:a 1 :b 2 :c 3}])
  
  (def data
    {:$schema "https://vega.github.io/schema/vega-lite/v4.json"
     :description "A simple bar chart with embedded data."
     :data {:values [{:a "A" :b 28} {:a "B" :b 55} {: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} {:a "J" :b 127}]}
     :mark "bar"
     :encoding {:x {:field "a" :type "ordinal"}
                :y {:field "b" :type "quantitative"}}})
  
  (code-add 3 (pr-str ^:R [:vega data] ))
  (result-set 3 ^:R [:vega data])
  
  (code-add 4 (pr-str ^:R  [:player "https://www.youtube.com/watch?v=Bs44qdAX5yo"]))
  (result-set 4 ^:R [:player "https://www.youtube.com/watch?v=Bs44qdAX5yo"])
  

awb99 avatar Mar 26 '20 03:03 awb99

A few more notes:

  1. currently it will only work when you run note-evaluations from pink-gorilla notebook (which I understand is not what we want). To run it from any project we just need to embed the compiled js bundle to the notebook; this should not be too hard to do.

  2. the meta info ^:R means it will create a reagent view - this allows full hiccup syntax for arbitrary renderer. the list of registered keywords appears when you click "show renderers" in the browser.

  3. markdown cells are missing, deleting cells missing

  4. the render magic happens in

(defn result-set
  "sends to browser instruction to set the result of an evaluation"
  [id result]
  (let [id-as-keyword (if (keyword? id) id (keyword (str id)))
        result-rendered (render-renderable-meta result)]
    (pinkie.server/send-all!
     [:pinkie/result-set {:id id-as-keyword :result result-rendered}])))
  1. instead of rendering to a static html file, we run webserver like oz; in fact most of the code was shamelessly stolen from oz.

awb99 avatar Mar 26 '20 04:03 awb99

Thanks @awb99 ! Looks great.

I'm getting this error trying to build the pinkie branch:

$ lein build-shadow-pinkie
Warning: implicit hook found: lein-environ.plugin/hooks 
Hooks are deprecated and will be removed in a future version.
Compiling 2 source files to /workspace/installations/gorilla-notebook/target/classes
Note: /workspace/installations/gorilla-notebook/src/java/pinkgorilla/NReplEndpoint.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
NPM dependency "react-dom" has installed version "^16.12.0"
"16.8.6" was required by jar:file:/home/daslu/.m2/repository/re-frame/re-frame/0.10.9/re-frame-0.10.9.jar!/deps.cljs
NPM dependency "react" has installed version "^16.12.0"
"16.8.6" was required by jar:file:/home/daslu/.m2/repository/re-frame/re-frame/0.10.9/re-frame-0.10.9.jar!/deps.cljs
[:pinkie] Compiling ...
The required namespace "cljs-time.format" is not available, it was required by "pinkgorilla/explore/utils.cljs".

Error encountered performing task 'run' with profile(s): 'base,system,user,provided,dev,pinkie'
Suppressed exit

daslu avatar Mar 27 '20 10:03 daslu

https://github.com/pink-gorilla/gorilla-notebook/commit/203136f74ca1fb8c089aa9bfe296c6dfc3fae445

please pull and try again. thanks!

awb99 avatar Mar 27 '20 15:03 awb99

Thanks @awb99 , now I get this:

$ lein build-shadow-pinkie
Warning: implicit hook found: lein-environ.plugin/hooks 
Hooks are deprecated and will be removed in a future version.
Compiling 2 source files to /workspace/installations/gorilla-notebook/target/classes
Note: /workspace/installations/gorilla-notebook/src/java/pinkgorilla/NReplEndpoint.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
NPM dependency "react-dom" has installed version "^16.12.0"
"16.8.6" was required by jar:file:/home/daslu/.m2/repository/re-frame/re-frame/0.10.9/re-frame-0.10.9.jar!/deps.cljs
NPM dependency "react" has installed version "^16.12.0"
"16.8.6" was required by jar:file:/home/daslu/.m2/repository/re-frame/re-frame/0.10.9/re-frame-0.10.9.jar!/deps.cljs
[:pinkie] Compiling ...
-> build target: :browser stage: :configure
<- build target: :browser stage: :configure (3 ms)
-> Resolving Module: :gorilla
<- Resolving Module: :gorilla (1301 ms)
-> build target: :browser stage: :compile-prepare
<- build target: :browser stage: :compile-prepare (0 ms)
-> Closure JS Cache read: 152 JS files
<- Closure JS Cache read: 152 JS files (59 ms)
-> Shadow JS Cache read: 307 JS files
<- Shadow JS Cache read: 307 JS files (126 ms)
-> Cache read: cljs/core.cljs
<- Cache read: cljs/core.cljs (50 ms)

...

------ ERROR -------------------------------------------------------------------
 File: jar:file:/home/daslu/.m2/repository/com/taoensso/encore/2.119.0/encore-2.119.0.jar!/taoensso/encore.cljs:1:1
--------------------------------------------------------------------------------

   1 | (ns taoensso.encore
-------^------------------------------------------------------------------------
Invalid :refer, macro taoensso.encore/-if-cas! does not exist
--------------------------------------------------------------------------------
   2 |   "Extended core library for Clojure/Script that emphasizes:
   3 |     * Cross platform API compatibility
   4 |     * Flexibility
   5 |     * Performance
--------------------------------------------------------------------------------

Error encountered performing task 'run' with profile(s): 'base,system,user,provided,dev,pinkie'
Suppressed exit

daslu avatar Mar 27 '20 16:03 daslu

Strange. I could not reproduce this issue. I looked into encore library, and it contains .cljx code files that get compiled to .clj and .cljs

Either something went wrong when encore published the version 2.119 to clojar You could change the encore dependency in project.clj to check for that. [com.taoensso/encore "2.117.0"] ; needed by sente

Or perhaps encore needs a higher version of clojure / clojurescript / shadow-cljs than you have installed.

awb99 avatar Mar 27 '20 19:03 awb99

@awb99 I tried from scratch on a different machine, and got this:

Warning: implicit hook found: lein-environ.plugin/hooks 
Hooks are deprecated and will be removed in a future version.
Compiling 2 source files to /workspace/installations/gorilla-notebook/target/classes
Note: /workspace/installations/gorilla-notebook/src/java/pinkgorilla/NReplEndpoint.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
NPM dependency "react-dom" has installed version "^16.12.0"
"16.8.6" was required by jar:file:/home/daslu/.m2/repository/re-frame/re-frame/0.10.9/re-frame-0.10.9.jar!/deps.cljs
NPM dependency "react" has installed version "^16.12.0"
"16.8.6" was required by jar:file:/home/daslu/.m2/repository/re-frame/re-frame/0.10.9/re-frame-0.10.9.jar!/deps.cljs
[:pinkie] Compiling ...
The required namespace "re-com.core" is not available, it was required by "pinkgorilla/widget/combo.cljs".

Error encountered performing task 'run' with profile(s): 'base,system,user,provided,dev,pinkie'
Suppressed exit

daslu avatar Apr 02 '20 16:04 daslu

https://github.com/pink-gorilla/gorilla-notebook/commit/ce70716ac9732ef5945234f0398481cb84cfa009

please checkout pinkie-fix. I added the missing dependency.

awb99 avatar Apr 03 '20 02:04 awb99

@awb99 thanks.

$ lein build-shadow-pinkie
Warning: implicit hook found: lein-environ.plugin/hooks 
Hooks are deprecated and will be removed in a future version.
Compiling 2 source files to /workspace/installations/gorilla-notebook/target/classes
Note: /workspace/installations/gorilla-notebook/src/java/pinkgorilla/NReplEndpoint.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Syntax error macroexpanding clojure.core/ns at (cljs/source_map/base64_vlq.clj:1:1).
((require [clojure.string :as string] [cljs.source-map.base64 :as base64])) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form

Full report at:
/tmp/clojure-8324044219198544478.edn
Error encountered performing task 'run' with profile(s): 'base,system,user,provided,dev,pinkie'
Suppressed exit

daslu avatar Apr 03 '20 07:04 daslu

Fixed. Please pull again.

I had some unresolved dependencies, that were all on my local ~/.m2 path. My fault, really.

BTW: I now tested that it works with nix shell. You can also run it,

./script/nix/nixInstall.sh                  (install nix shell)
./script/nix/nixBuildPinkie.sh
./script/nix/nixRunPinkie.sh 

awb99 avatar Apr 05 '20 17:04 awb99

The build works, thanks!

daslu avatar Apr 05 '20 19:04 daslu

image Got this on the browser.

daslu avatar Apr 05 '20 19:04 daslu

please run lein build-tailwind-dev

awb99 avatar Apr 06 '20 04:04 awb99

also you need to open / and not worksheet.html

awb99 avatar Apr 06 '20 04:04 awb99

Hi @awb99 . I am now using commit 7d34cccba219ef2104b4a479cdcf68f7a27a0b65, which is the latest of pinkie-fix.

Getting this:

$ lein run-pinkie
Warning: implicit hook found: lein-environ.plugin/hooks 
Hooks are deprecated and will be removed in a future version.
Could not find artifact reagent:reagent:jar:0.10.1 in central (https://repo1.maven.org/maven2/)
Could not find artifact reagent:reagent:jar:0.10.1 in clojars (https://repo.clojars.org/)
This could be due to a typo in :dependencies, file system permissions, or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.
Error encountered performing task 'run' with profile(s): 'base,system,user,provided,dev,pinkie'
Suppressed exit

daslu avatar Apr 08 '20 23:04 daslu

Also:

$ lein repl
Warning: implicit hook found: lein-environ.plugin/hooks 
Hooks are deprecated and will be removed in a future version.
#error {
 :cause Could not locate shadow/cljs/devtools/api__init.class, shadow/cljs/devtools/api.clj or shadow/cljs/devtools/api.cljc on classpath.
 :via
 [{:type clojure.lang.Compiler$CompilerException
   :message Syntax error compiling at (pinkgorilla/repl.clj:1:1).
   :data #:clojure.error{:phase :compile-syntax-check, :line 1, :column 1, :source pinkgorilla/repl.clj}
   :at [clojure.lang.Compiler load Compiler.java 7648]}
  {:type java.io.FileNotFoundException
   :message Could not locate shadow/cljs/devtools/api__init.class, shadow/cljs/devtools/api.clj or shadow/cljs/devtools/api.cljc on classpath.
   :at [clojure.lang.RT load RT.java 462]}]
 :trace
 [[clojure.lang.RT load RT.java 462]
  [clojure.lang.RT load RT.java 424]
  [clojure.core$load$fn__6839 invoke core.clj 6126]
  [clojure.core$load invokeStatic core.clj 6125]
  [clojure.core$load doInvoke core.clj 6109]
  [clojure.lang.RestFn invoke RestFn.java 408]
  [clojure.core$load_one invokeStatic core.clj 5908]
  [clojure.core$load_one invoke core.clj 5903]
  [clojure.core$load_lib$fn__6780 invoke core.clj 5948]
  [clojure.core$load_lib invokeStatic core.clj 5947]
  [clojure.core$load_lib doInvoke core.clj 5928]
  [clojure.lang.RestFn applyTo RestFn.java 142]
  [clojure.core$apply invokeStatic core.clj 667]
  [clojure.core$load_libs invokeStatic core.clj 5985]
  [clojure.core$load_libs doInvoke core.clj 5969]
  [clojure.lang.RestFn applyTo RestFn.java 137]
  [clojure.core$apply invokeStatic core.clj 667]
  [clojure.core$require invokeStatic core.clj 6007]
  [clojure.core$require doInvoke core.clj 6007]
  [clojure.lang.RestFn invoke RestFn.java 482]
  [pinkgorilla.repl$eval149$loading__6721__auto____150 invoke repl.clj 1]
  [pinkgorilla.repl$eval149 invokeStatic repl.clj 1]
  [pinkgorilla.repl$eval149 invoke repl.clj 1]
  [clojure.lang.Compiler eval Compiler.java 7177]
  [clojure.lang.Compiler eval Compiler.java 7166]
  [clojure.lang.Compiler load Compiler.java 7636]
  [clojure.lang.RT loadResourceScript RT.java 381]
  [clojure.lang.RT loadResourceScript RT.java 372]
  [clojure.lang.RT load RT.java 459]
  [clojure.lang.RT load RT.java 424]
  [clojure.core$load$fn__6839 invoke core.clj 6126]
  [clojure.core$load invokeStatic core.clj 6125]
  [clojure.core$load doInvoke core.clj 6109]
  [clojure.lang.RestFn invoke RestFn.java 408]
  [clojure.core$load_one invokeStatic core.clj 5908]
  [clojure.core$load_one invoke core.clj 5903]
  [clojure.core$load_lib$fn__6780 invoke core.clj 5948]
  [clojure.core$load_lib invokeStatic core.clj 5947]
  [clojure.core$load_lib doInvoke core.clj 5928]
  [clojure.lang.RestFn applyTo RestFn.java 142]
  [clojure.core$apply invokeStatic core.clj 667]
  [clojure.core$load_libs invokeStatic core.clj 5985]
  [clojure.core$load_libs doInvoke core.clj 5969]
  [clojure.lang.RestFn applyTo RestFn.java 137]
  [clojure.core$apply invokeStatic core.clj 667]
  [clojure.core$require invokeStatic core.clj 6007]
  [clojure.core$require doInvoke core.clj 6007]
  [clojure.lang.RestFn invoke RestFn.java 408]
  [user$eval5 invokeStatic form-init5506061197502927919.clj 1]
  [user$eval5 invoke form-init5506061197502927919.clj 1]
  [clojure.lang.Compiler eval Compiler.java 7177]
  [clojure.lang.Compiler eval Compiler.java 7166]
  [clojure.lang.Compiler eval Compiler.java 7166]
  [clojure.lang.Compiler load Compiler.java 7636]
  [clojure.lang.Compiler loadFile Compiler.java 7574]
  [clojure.main$load_script invokeStatic main.clj 475]
  [clojure.main$init_opt invokeStatic main.clj 477]
  [clojure.main$init_opt invoke main.clj 477]
  [clojure.main$initialize invokeStatic main.clj 508]
  [clojure.main$null_opt invokeStatic main.clj 542]
  [clojure.main$null_opt invoke main.clj 539]
  [clojure.main$main invokeStatic main.clj 664]
  [clojure.main$main doInvoke main.clj 616]
  [clojure.lang.RestFn applyTo RestFn.java 137]
  [clojure.lang.Var applyTo Var.java 705]
  [clojure.main main main.java 40]]}
Error loading shadow.cljs.devtools.server.nrepl: Could not locate shadow/cljs/devtools/server/nrepl__init.class, shadow/cljs/devtools/server/nrepl.clj or shadow/cljs/devtools/server/nrepl.cljc on classpath.
Syntax error compiling var at (/tmp/form-init5506061197502927919.clj:1:3099).
Unable to resolve var: shadow.cljs.devtools.server.nrepl/middleware in this context

Full report at:
/tmp/clojure-2686399469790054390.edn
Subprocess failed

daslu avatar Apr 08 '20 23:04 daslu