Database Reference
In-Depth Information
First, we'll set up a web application with Ring (
https://github.com/ring-clojure/
and web applications. Compojure is a small web framework that provides a convenient way
to deine and handle routes (the associations between URLs and functions to provide data
for them).
order to generate HTML from data structures.
We'll complete our web stack with ClojureScript (
https://github.com/clojure/
clojurescript
). This is just Clojure, but instead of compiling to a JVM, it compiles to
JavaScript. We can load its output into our web pages and use it to create stunning graphs.
The rest of the chapter will involve what we can create using this Clojure-dominated web
libraries to create visualizations from the data. In the end, we'll wind up with some good
graphs and a productive environment to publish the results of our data analysis.
The stack from this chapter can be easily deployed to services such as Heroku
of this system and to make our information available to the general public.
Serving data with Ring and Compojure
While we can precompile ClojureScript and load the generated JavaScript iles as static
assets, we'll often want to combine the dynamic charts with dynamic pages. For instance,
we might want to provide a search form to ilter the data that's graphed.
In this recipe, we'll get started with a typical Clojure web stack. Even if we don't use
ClojureScript, this system is useful for creating web applications. We'll use Jetty (
http://
ring-clojure/ring
)
to connect the server to the different parts of our web application,
Getting ready
We'll irst need to include Jetty, Ring, and Compojure in our Leiningen
project.clj
ile.
We'll also want to use Ring as a development plugin for this project, so let's include it in the
project.clj
ile under the
:plugins
key. The following is the full Leiningen project ile:
(defproject web-viz "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.6.0"]
[ring/ring-core "1.3.1"]