is there a view-as-html function for an incanter dataset ?

52 views
Skip to first unread message

A

unread,
Apr 23, 2013, 7:45:35 PM4/23/13
to inca...@googlegroups.com

I'm looking for a way to render a small Incanter dataset as html markup, Hiccup style, into something that looks like an HTML table. 
For example,  to view the Iris dataset as HTML something like this:

(use 'incanter.core)
(use 'incanter.datasets)

(view-as-html (get-dataset :iris))

Does something akin to a "view-as-html" function already exist?

Thanks,
Avram


greg r

unread,
Apr 24, 2013, 11:02:49 AM4/24/13
to inca...@googlegroups.com

You could use emacs org babel and export the document to HTML.  I haven't done this myself, but I think it would work.  It would be an indirect, but usable solution.

A

unread,
Jun 14, 2013, 3:31:57 AM6/14/13
to inca...@googlegroups.com
I finally took a stab at this. Still tinkering but looking for feedback...
;; i is incanter.core

(defn view-as-html [incanter-dataset]                                                                                                                                                         
  [:table {:border 0}                                                                                                                                                                         
   [:thead                                                                                                                                                                                    
    [:tr                                                                                                                                                                                      
     (for [field-name (i/col-names incanter-dataset)]                                                                                                                                         
       [:th field-name])]]                                                                                                                                                                    
   [:tbody                                                                                                                                                                                    
    (for [r (second (second incanter-dataset))]                                                                                                                                               
      [:tr  (for [k (i/col-names incanter-dataset) ]                                                                                                                                          
              [:td (str (k r))]                                                                                                                                                               
              )])]]) 

does this look reasonable?

Cheers,
-A
Reply all
Reply to author
Forward
0 new messages