Loading...
 

rCharts

http://rcharts.io
http://rcharts.io

rCharts is an R package to create, customize and publish interactive javascript visualizations from R using a familiar lattice style plotting interface. It has been created by Ramnath Vaidyanathan. See more here: http://rcharts.io/

Below you will find a series of examples of nice charts using rCharts and the corresponding javascript library used in each case.

Page contents:


Introduction

For these examples to work in a website, you need to change the location of the library they look for. By default they are set to use the library included in the R package rCharts, but the webserver usually can't access directly those libraries, since they are out of its reach. To avoid this issue, we can create an alias in the apache configuration for the website.

You need to open the apache configuration file, whch might be located at /etc/apache2/sites-enabled/000-default (adapt to your case)
Command to open the file for edition in a shell as root
nano /etc/apache2/sites-enabled/000-default


If you have Apache 2.2 (e.g. in Ubuntu 12.04 servers):
Portion to add to /etc/apache2/sites-enabled/000-default or equivalent for your site with Apache 2.2
Alias /rcharts_libraries/ "/usr/local/lib/R/site-library/rCharts/libraries/"
	<Directory "/usr/local/lib/R/site-library/rCharts/libraries/">
	    Options All
	    AllowOverride All
	    Order allow,deny
	    Allow from all
	</Directory>


If you have Apache 2.4 (e.g. in Ubuntu 12.04 servers):
Portion to add to /etc/apache2/sites-enabled/000-default or equivalent for your site with Apache 2.4
Alias /rcharts_libraries/ "/usr/local/lib/R/site-library/rCharts/libraries/"
	<Directory "/usr/local/lib/R/site-library/rCharts/libraries/">
	    Options All
	    AllowOverride All
        #Order allow,deny
        #Allow from all
        Require all granted
	</Directory>

Then you can save it (-+Ctrl+X+- in nano editor)

The whole configuration file for the site should look like the example below in Apache 2.4 (adapt it to your case):
Example of configuration file for the website
<VirtualHost *:80>
	ServerAdmin webmaster@example.com

	DocumentRoot /var/www
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /var/www/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
#		Order allow,deny
		Satisfy Any
        #Order allow,deny
        #Allow from all
        Require all granted
	</Directory>

	Alias /rcharts_libraries/ "/usr/local/lib/R/site-library/rCharts/libraries/"
	<Directory "/usr/local/lib/R/site-library/rCharts/libraries/">
	    Options All
	    AllowOverride All
        #Order allow,deny
        #Allow from all
        Require all granted
	</Directory>

	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
	<Directory "/usr/lib/cgi-bin">
		AllowOverride None
		Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        #Order allow,deny
        #Allow from all
        Require all granted
	</Directory>

	ErrorLog ${APACHE_LOG_DIR}/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


Then restart the webserver (adapt to your case):
Command to restart apache2 in GNU/Linux boxes as root
service apache2 restart


At this time you can already use the javascript and css files provided in the package rCharts from your R scripts in Tiki, with the base url http://example.com/rcharts_libraries/

Tweaks for Apache 2.4

If you have the webserver Apache 2.4 (likely if you have Ubuntu 13.10 Saucy, for instance), the you need to adjust your vhost:

1. First: +/- on Options:
Some Options parameters needs the +/- syntax. Read more here. This might be especially important when mixing +/- on some directives (read the previous link to see more).

Change:
Options Indexes FollowSymLinks MultiViews


to:
Options +Indexes +FollowSymLinks +MultiViews


2. Second: Allow/Deny
Apache now does access control via mod_authz_host

Change:

Order allow,deny
Allow from all


to:
Require all granted


Some more info here on upgrading from Apache 2.2 to 2.4.

Examples



Credits


Most of the implementation in rCharts seems to be inspired by rHighcharts and rVega. The author have reused some code from these packages verbatim, and would like to acknowledge the efforts of its corresponding author Thomas Reinholdsson.

License


rCharts is licensed under the MIT License. However, the Polycharts JavaScript library that is included in this package is not free for commercial use, and is licensed under Creative Commons 3.0 Attribution & Non-commercial. Read more about its license at http://polychart.com/js/license.