==============================
Data preview and visualization
==============================
.. contents::
Overview
--------
The CKAN resource page can contain one or more visualizations of the resource
data or file contents (a table, a bar chart, a map, etc). These are commonly
referred to as *resource views*.
.. image:: /images/views_overview.png
The main features of resource views are:
* One resource can have multiple views of the same data (for example a grid
and some graphs for tabular data).
* Dataset editors can choose which views to show, reorder them and configure
them individually.
* Individual views can be embedded on external sites.
Different view types are implemented via custom plugins, which can be activated
on a particular CKAN site. Once these plugins are added, instance
administrators can decide which views should be created by default if the
resource is suitable (for instance a table on resources uploaded to the
DataStore, a map for spatial data, etc.).
Whether a particular resource can be rendered by the different view plugins is
decided by the view plugins themselves. This is generally done checking the
resource format or whether its data is on the :doc:`datastore` or
not.
Managing resource views
-----------------------
Users who are allowed to edit a particular dataset can also manage the views
for its resources. To access the management interface, click on the *Manage*
button on the resource page and then on the *Views* tab. From here you can
create new views, update or delete existing ones and reorder them.
.. image:: /images/manage_views.png
The *New view* dropdown will show the available view types for this particular
resource. If the list is empty, you may need to add the relevant view plugins
to the :ref:`ckan.plugins` setting on your configuration file, eg::
ckan.plugins = ... image_view datatables_view pdf_view
Defining views to appear by default
-----------------------------------
From the management interface you can create and edit views manually, but in most
cases you will want views to be created automatically on certain resource types,
so data can be visualized straight away after uploading or linking to a file.
To do so, you define a set of view plugins that should be checked whenever a
dataset or resource is created or updated. For each of them, if the resource is
a suitable one, a view will be created.
This is configured with the :ref:`ckan.views.default_views` setting. In it you
define the view plugins that you want to be created as default::
ckan.views.default_views = datatables_view pdf_view geojson_view
This configuration does not mean that each new resource will get all of these
views by default, but that for instance if the uploaded file is a PDF file,
a PDF viewer will be created automatically and so on.
Available view plugins
----------------------
Some view plugins for common formats are included in the main CKAN repository.
These don't require further setup and can be directly added to the
:ref:`ckan.plugins` setting.
DataTables view
+++++++++++++++
.. image:: /images/datatables_view.png
View plugin: ``datatables_view``
Displays a filterable, sortable, table view of structured data using the
DataTables_ jQuery plugin, with the following features.
* Search highlighting
* Column Filters
* Multi-column sorting
* Two view modes (table/list). Table shows the data in a typical grid with
horizontal scrolling. List displays the data in a responsive mode, with
a Record Details view.
* Filtered Downloads
* Column Visibility control
* Copy to clipboard and Printing of filtered results and row selection/s
* Drag-and-drop column reordering
* State Saving - saves search keywords, column order/visibility, row
selections and page settings between session, with the ability to share
saved searches.
* Data Dictionary Integration
* Automatic "linkification" of URLs
* Automatic creation of zoomable thumbnails when a cell only contains a URL
to an image.
* Available automatic, locale-aware date formatting to convert raw ISO-8601
timestamps to a user-friendly date format
It is designed not only as a data viewer, but also as a simple ad-hoc report
generator - allowing users to quickly find an actionable subset of
the data they need from inside the resource view, without having to first
download the dataset.
It's also optimized for embedding datasets and saved searches on external
sites - with a backlink to the portal and automatic resizing.
This plugin requires data to be in the DataStore.
Text view
+++++++++
.. image:: /images/text_view.png
View plugin: ``text_view``
Displays files in XML, JSON or plain text based formats with the syntax
highlighted. The formats detected can be configured using the
:ref:`ckan.preview.xml_formats`, :ref:`ckan.preview.json_formats`
and :ref:`ckan.preview.text_formats` configuration options respectively.
If you want to display files that are hosted in a different server from your
CKAN instance (eg that haven't been uploaded to CKAN) you will need to enable
the `Resource Proxy`_ plugin.
Image view
++++++++++
.. image:: /images/image_view.png
View plugin: ``image_view``
If the resource format is a common image format like PNG, JPEG or GIF, it adds
an ```` tag pointing to the resource URL. You can provide an alternative
URL on the edit view form. The available formats can be configured using the
:ref:`ckan.preview.image_formats` configuration option.
Video view
++++++++++
.. image:: /images/video_view.png
View plugin: ``video_view``
This plugin uses the HTML5