Plugin R | |||||
This Wiki Plugins provides an interface to run R scripts through web pages. PluginR allows basic and direct usage, writing the script between the PluginR tags (see below), but it also allows advanced usage, where Pretty Trackers can be used to make web interfaces to modify the parameters that you want to allow the user to modify before producing the text or graphic output from your scripts. Or you can send full data files to your R script to be processed and get the output automatically on-line a few seconds later. This way, Tiki and PluginR become a nice and collaborative web interface for your custom R scripts. Up to Tiki17 you needed to install this plugin separately from Tiki through Mods. Starting in Tiki18, some plugin parts were rewritten to avoid former license incompatibilities with Tiki, so that it is bundled within the main Tiki code base, and no extra installation is needed for PluginR to work, aside of the R engine in the server, as usual.
Is this your first time to R or Tiki? New to R?
For more information, see: http://www.r-project.org. New to Tiki?
To run Tiki you need:
|
Try it at r.tiki.org | |
Try it here: https://r.tiki.org |
Installation (if Tiki < 18) | |
This plugin is not installed by default in Tiki until Tiki18 (it was GPL licensed before then, while Tiki is LGPL licensed), therefore for Tiki versions earlier than 18, you can obtain it from Mods. You can see the details of the last version here:
And you can fetch it from a link like (being X.YY the latest version of the plugin; e.g. 0.70):
See the documentation about Mods to see how to manually install a Mod in your Tiki site. In its current design, it will only work in Unix-like environments, such as GNU/Linux and others. It comes with two plugin files (wikiplugin_r.php and wikiplugin_rr.php), and one .htaccess file to allow writing .png files (for charts and figures) at the ./temp folder in tiki. Please note: you will need to have the php function exec enabled on your server to run wikiplugin_rr.php Additionally, you might want to install the "geshi" program in your tiki file tree (as explained in PluginCode ), so that you can get color highlighting when documenting bits of R syntax inside PluginCode calls. Since Tiki7 you can alternatively enable the feature "Syntax highlighting" (codemirror) bundled within Tiki in order to get this result and also syntax highlighting while in edit mode. See Syntax Highlighter |
Requirements | |
The R package and imagemagick installed in the server. On GNU/Linux and similar systems, you can install the base packages with something like: Copy to clipboard
or Copy to clipboard
depending on the GNU/Linux distribution that you use. If you see an error message saying something about an error when attempting to convert..., then you need to ensure that you installed the system package imagemagick, that will be needed for image conversion server side in R. Once all requirements are installed, you can start the R console in a terminal by typing "R". You might need some extra R packages in your R installation, depending on the type of analysis that you want R to perform for you. For instance, depending on which R packages you want to use, you might need to install these system packages additionally, in order to have the other specific packages working (from debian GNU/Linux system, or similar name under other GNU/Linux distributions) Copy to clipboard
Copy to clipboard
Copy to clipboard
Copy to clipboard
|
Usage and Parameters | |
To use this plugin in a wiki page, use the syntax: Copy to clipboard
Copy to clipboard
|
Plugin R vs Plugin RR | |
Since version 0.5.1 from this mod, you can use plugin rr to execute as admin unsafe commands: you will be required admin validation of those plugin calls. With plugin r, you will not be requested plugin validation, instead, but unsafe commands will be blocked.
|
Parameters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Display several graphs in the same Plugin R call | |
Copy to clipboard
|
Set a CRAN mirror in your R call | |
You can setup a CRAN mirror in your R call at the wiki page level, by means of using this code: Copy to clipboard
|
Find results through the tiki search | |
Tiki is able to index the results from plugin R. You just need to add "r" and "rr" in the list of plugins to be indexed their contents (which also indexes their results) You can do so in the Search Control Panel (tiki-admin.php?page=search):
|
Examples | |
|
1.1.1. Example 1: simple command | |
Copy to clipboard
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
1.1.2. Example 2: a simple graph | |
Copy to clipboard
|
1.1.3. Example 3 | |
Opening a file from a tracker item attachment and let the R script use it, showing the output in the wiki page. http://www.geography.uoregon.edu/GeogR/topics/examplesession.htm Get this file sumcr.csv as example:
When opened in a text editor, it should look like (with 89 lines, instead of just those following 4): Copy to clipboard
1.1.3.1. 3a: attId hardcodedCreate a wiki page with a call to the PluginR, setting the attId in the appropriate param of the plugin.
attId=2. csv file with csv extension. data separated with commas Copy to clipboard
The data in that csv file has been assigned to the variable data in the pluginR.
Output produced: Copy to clipboard
1.1.3.2. 3b: attId dynamically referencedA page A with a PluginTrackerList lists items from a tracker with the param link=y. The url param has to be like: ur When the users click on the link of an item, they are sent to wiki page B, with an url containing the Id number of that traker item selected. PluginR gets then the attachment id of that tracker item, in order to use it to populate the variable "data". The syntax, in this other example, is as follows: Copy to clipboard
However, right now, if there is not itemId passed through the url, the R plugin runs and shows some output error on the wiki page. To see this example in action, install the Profile http://profiles.tiki.org/r_test |
1.1.4. Example 4: producing graphs | |
Copy to clipboard
|
1.1.5. Example 5: adding params to the graphs | ||||||
|
1.1.6. Example 6: edit R params through Pretty Trackers | |
What are "Pretty Trackers" in the Tiki context?
|
1.1.7. Example 7: showing results in html | |
1.1.7.1. Using html tagsThis code: Copy to clipboard
[1] "hello" 1.1.7.2. Using wikisyntax param: no param set
Copy to clipboard
[1] "__hello__" 1.1.7.3. Using wikisyntax param set to 0
Copy to clipboard
[1] "__hello__" 1.1.7.4. Using wikisyntax param set to 1
Copy to clipboard
1 "hello"
|
1.1.8. Example 8: using potentially dangerous commands | |
As an admin you can execute any R command to the server. Just plugin rr instead, and validate your plugin calls as needed. Normal users don't have the ability to validate plugin calls, so that they can only execute safe R commands in the server. |
1.1.9. Example 9: loading and saving the R workspace | |
By default Plugin R runs in --vanilla mode, so that no workspace is loaded at the beginning nor saved at the end, and no human intervention is expected to run the R commands, nor echo's from the R console are printed. However, for some use cases, you may need to save the R objects and data from your session (call to PluginR) and re-use it afterwards in a new PluginR call, in the same wiki page or others. 1.1.9.1. In the same wiki pageIf you have more than one call to PluginR in the same wiki page, you can use the param. loadandsave to force R to load any existing workspace data for that wiki page and save it at the end again. For instance, for a Wiki page called "My Test", you would have your workspace data stored in your server at: Copy to clipboard
Example:
1.1.9.2. Across diferent wiki pagesIn this case, we assume that all wiki pages involved in your R calls are a set of scripts that can be run for multiple analysis on one or more of your r scripts. This way, we'll use the Trackers feature, which will serve as a database engine to keep track of all our analysis projects, with the addition to keep the same workspace data among all pages related to the same project. Therefore, as far as the itemId param is used in the urls sent between wiki pages (by means of PluginTrackerList, or other tracker-related plugins), the same workspace will be used even if different wiki pages are involved. Workspace data is stored under the ./temp/cache/ directory. E.g., for project with itemId 33, the workspace will be saved at: Copy to clipboard
|
Current limitations | |
|
Tips | |
Some useful tips for advanced usage:
|
External sources of information | |
Related presentation at UseR! 2011 | |
UseR! 2011: http://www.warwick.ac.uk/statsdept/user-2011/
|
Discussion Forums | |
|
Publications | |
There are some publications/communications already based on the usage on Tiki & PluginR in different scientific fields:
References and links
alias
|