-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add function to show data in browser #9
Comments
Tables are definitely something that should be added. I actually have a rather provisional implementation built on top of (Datatables)[https://datatables.net/] that we used internally at GoOpti. Here's the code if you can lift any ideas from it. PR very welcome. (defn table
([df]
(table {} df))
([opts df]
(let [{:keys [limit sort-by pagination? header-column? columns filtering?]
:or {limit 5
pagination? true
filtering? false}} opts
id (name (gensym "df"))
headers (zipmap (cols df) (range))
order (let [[sort-col sort-direction] (-> sort-by
(or (ffirst headers))
ensure-seq)]
(format "order: [[%s, '%s']]" (safe-get headers sort-col)
(name (or sort-direction :asc))))
pagination (format "bPaginate: %s" pagination?)
info (format "info: %s" pagination?)
filtering (format "bFilter: %s" filtering?)
dt-options (s/join "," [order pagination info filtering])
columns (or columns (keys headers))]
(->> (list [:table.stripe.hover.cell-border {:id id}
[:thead
[:tr (for [h columns]
[:th (name h)])]]
[:tbody (for [row (if (= limit :all)
df
(take limit df))]
[:tr (map-indexed (fn [i cell]
[(if (and header-column?
(zero? i))
:th
:td) cell])
((apply juxt columns) row))])]]
(javascript-tag (format "$('#%s').DataTable({%s});"
id dt-options)))
html
html-view)))) |
I hacked as well an other version based on datatables. Will look at yours know. |
I could not find function html-view. |
https://github.com/JonyEpsilon/gorilla-repl/blob/v0.3.5/src/gorilla_repl/html.clj Looks like Gorilla changed a bit in the last year. I was using a custom version and wasn't tracking changes he was making. |
Ok, I see. It's for rendering the table as part of Gorilla repl. I use huri currently without Gorilla. If I look at the upper "table" function, it would be idenpendent of Gorilla, removing the last line. My first use case would be to have a function which produced from a "sequence of maps" a STANDALONE html file, which I could then render in a "(open-in-browser html)" function. So maybe the right approach here could be (given the potential complexity of data table configuration) to take your code from above and make it return just the hicupp data structure, so removing the last two lines. Maybe call it This could then be reused for both cases:
The first function would then probbaly not be part of huri, What do you think ? |
I started to use huri and it's idea of a "data-set is sequences of maps" and one of the first things I wanted to add, for the "layz data scientist", is to show a "sequence of maps in a browser".
The code for thjis looks like this:
So it would add depencies to hiccup and friends:
Let me know, if you think this could fit here, so I do a PR
Something similar could be done using "clojure.inspect" (while I like to html look better)
The text was updated successfully, but these errors were encountered: