Web Development with R



Similar documents
Web Development with R

Introduction Simple Web Application Advanced Web Application IRT tool Screenshots. IRTTool.com. Building web applications with R.

Introduction to Web Development with R

A Tool for Evaluation and Optimization of Web Application Performance

GUI and Web Programming

An introduction to creating Web 2.0 applications in Rational Application Developer Version 8.0

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

Speed up your web site. Alan Seiden Consulting alanseiden.com

Example. Represent this as XML

Rich User Interfaces for Web-Based Corporate Applications

WEB DEVELOPMENT COURSE (PHP/ MYSQL)

MASTERTAG DEVELOPER GUIDE

HtmlUnit: An Efficient Approach to Testing Web Applications

603: Enhancing mobile device experience with NetScaler MobileStream Hands-on Lab Exercise Guide

Implementing Mobile Thin client Architecture For Enterprise Application

DiskPulse DISK CHANGE MONITOR

10CS73:Web Programming

Developer Tutorial Version 1. 0 February 2015

AUTOMATED CONFERENCE CD-ROM BUILDER AN OPEN SOURCE APPROACH Stefan Karastanev

Bug Report. Date: March 19, 2011 Reporter: Chris Jarabek

Outline. CIW Web Design Specialist. Course Content

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator

Advanced Web Development SCOPE OF WEB DEVELOPMENT INDUSTRY

Visualizing a Neo4j Graph Database with KeyLines

How to Code With MooTools

Apple Applications > Safari

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

Web Design Specialist

How To Test Your Web Site On Wapt On A Pc Or Mac Or Mac (Or Mac) On A Mac Or Ipad Or Ipa (Or Ipa) On Pc Or Ipam (Or Pc Or Pc) On An Ip

Version 1.0 January Xerox Phaser 3635MFP Extensible Interface Platform

Fachgebiet Technische Informatik, Joachim Zumbrägel

Web-JISIS Reference Manual

LabVIEW Internet Toolkit User Guide

Facebook Twitter YouTube Google Plus Website . o Zooming and Panning. Panel. 3D commands. o Working with Canvas

Visualizing an OrientDB Graph Database with KeyLines

RIA Technologies Comparison

Session D15 Simple Visualization of your TimeSeries Data. Shawn Moe IBM

Survey Public Visualization Services

Intro to Web Programming. using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000

Rich-Internet Anwendungen auf Basis von ColdFusion und Ajax

Platform Independent Mobile Application Development

Google Web Toolkit. Introduction to GWT Development. Ilkka Rinne & Sampo Savolainen / Spatineo Oy

An introduction to creating JSF applications in Rational Application Developer Version 8.0

Progressive Enhancement With GQuery and GWT. Ray Cromwell

design coding monitoring deployment Java Web Framework for the Efficient Development of Enterprise Web Applications

Load Testing Ajax Apps using head-less browser tools. NoVaTAIG April 13, 2011 Gopal Addada and Frank Hurley Cigital Inc.

Application layer Web 2.0

Friday, February 11, Bruce

Skills for Employment Investment Project (SEIP)

Using Ajax for Desktop-like Geospatial Web Application Development

IBM Script Portlet for WebSphere Portal Release 1.1

Getting Started Guide with WIZ550web

Design Approaches of Web Application with Efficient Performance in JAVA

Lucy Zhang UI Developer Contact:

University of Auckland

DreamFactory & Modus Create Case Study

Embedded BI made easy

Performance Testing for Ajax Applications

Web Performance First Aid. Alan Seiden Consulting alanseiden.com

CMSC434 TUTORIAL #3 HTML CSS JavaScript Jquery Ajax + Google AppEngine Mobile WebApp HTML5

Team Members: Christopher Copper Philip Eittreim Jeremiah Jekich Andrew Reisdorph. Client: Brian Krzys

Debugging JavaScript and CSS Using Firebug. Harman Goei CSCI 571 1/27/13

ArcGIS Server mashups

Shipbeat Magento Module. Installation and user guide

Web Performance. Lab. Bases de Dados e Aplicações Web MIEIC, FEUP 2014/15. Sérgio Nunes

How to start with 3DHOP

An evaluation of JavaFX as 2D game creation tool

Introduction to the. Barracuda Embedded Web-Server

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

CLASSROOM WEB DESIGNING COURSE

FormAPI, AJAX and Node.js

WIRIS quizzes web services Getting started with PHP and Java

A set-up guide and general information to help you get the most out of your new theme.

Software Development & Education Center PHP 5

ArcGIS Web App Builder (AWAB) In BETA. John Bocan MES/DoIT

Rich Internet Applications

Design Requirements for an AJAX and Web-Service Based Generic Internet GIS Client

Binonymizer A Two-Way Web-Browsing Anonymizer

Lecture 9 Chrome Extensions

MO 25. Aug. 2008, 17:00 UHR RICH INTERNET APPLICATIONS MEHR BISS FÜR WEBANWENDUNGEN

^/ CS> KRIS. JAMSA, PhD, MBA. y» A- JONES & BARTLETT LEARNING

Advantage of Jquery: T his file is downloaded from

HP LoadRunner. Software Version: Ajax TruClient Tips & Tricks

Overview. In the beginning. Issues with Client Side Scripting What is JavaScript? Syntax and the Document Object Model Moving forward with JavaScript

From Desktop to Browser Platform: Office Application Suite with Ajax

COS 333: Advanced Programming Techniques

Braindumps.C questions

Serving dynamic webpages in less than a millisecond

Mobile development with Apache OFBiz. Ean Schuessler, Brainfood

Joomla! template JSN Mico Customization Manual

Step into the Future: HTML5 and its Impact on SSL VPNs

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

Developing ASP.NET MVC 4 Web Applications

PHP on IBM i: What s New with Zend Server 5 for IBM i

General principles and architecture of Adlib and Adlib API. Petra Otten Manager Customer Support

Developing ASP.NET MVC 4 Web Applications Course 20486A; 5 Days, Instructor-led

FileMaker Server 15. Custom Web Publishing Guide

Upgrade to Microsoft Web Applications

Course Information Course Number: IWT 1229 Course Name: Web Development and Design Foundation

Abdullah Radwan. Target Job. Work Experience (9 Years)

Transcription:

Web Development with R Bay Area user Group Jeroen Ooms jeroenooms@gmail.com January 2010, San Francisco

R and Javascript: A match made in heaven? R and Javascript have a lot in common: Both accessible, loose scripting languages. Both have big and quickly growing communities. Both have lots of libraries/packages available. Both have become de facto standards (by accident?). Both don t like Java. But they also complete each other: R is powerfull: interfaces C, Fortran, Databases, Latex, etc. Many computing packages available. Javascript is nice for the user, interfaces to DOM, CSS, many widget/design packages available.

What is a Web Application Some examples: yeroon.net/ggplot2 [video] yeroon.net/lme4 [video] Pubertyplot [video] Stockplot [video] IRT tool [video]

What is a Web Application This presentation is about: Making Web Interfaces for Simple R applications. R runs on the server. User only needs a standard webbrowser. Programming in R and HTML/Javascript (No Java!). AJAX interfaces. It is not about: Applications that require advanced queueing systems for running multiple simultaneous R jobs. Distributed Computing. Java.

Why Web Applications? Convenient: Making new tools available to a wide audience. User only needs a standard webbrowser. Cross-platform. Server-based by design: Efficient use of resources. Easier to maintain. Integration with existing services/databases/etc. Because you have to: More and more services only available from the browser. Many people can t or dont want to install software.

Hello World! RApache RApache is a module for the Apache web server. It allows you to embed R scripts in a webpage. It is one of the ways of connecting the HTTPD to R. Demo: Brew scripting. GET/POST. Try Catch.

Web application Setup Server Client Request/Response Workstation Calling R Interface

ggplot2 example 1. Interface: Interactive webpage with menu, buttons, layer list, etc, that enables the user to specify a plot. 2. Request: A configuration of a plot to draw (settings, mappings, layers) 3. Server: Decodes the configuration, and draws the requested figure. 4. Response: The plot figure. 5. Interface: Updates figure within the page, and makes appropriate changes in GUI.

The Message Specification Where the magic happens: How to get objects from the client s browser into R on the server? HTTP basically only takes strings for arguments. Protocol Design: Maintain a request object in the browser (client). Define a way to encode your javascript object into a string. Use this string as argument to an HTTP/AJAX request. Decode the string on the server back to an object. Idem for the response message.

Message Specification: XML and JSON. For advanced web applications use a standard data format to communicate with the server. 2 obvious candidates: XML and JSON. You can use CRAN packages XML and rjson for parsing. XML is most widely used, probably preferable if you want to integrate your application in other software (consider SOAP). JSON is lighter and supports array s. Preferred for large datasets.

Example of XML Syntax <mymodel> <family>gaussian</family> <deviance>3569.23</deviance> <coefficients> <coef> <name>intercept</name> <value>5.69</value> </coef> <coef> <name>age</name> <value>0.36</value> </coef> <coef> <name>gender</name> <value>2.54</value> </coef> </coefficients> </mymodel>

Example of JSON Syntax {"mymodel": { "family": "Gaussian", "deviance": 3569.23, "coefficients": [ {"Intercept": 5.69}, {"Age": 0.36}, {"Gender": 2.54} ] } } Or for example a dataframe: {"mydata": { "Age":[9,8,12,6,7,8,9,8,10,11,9,6,8], "Gender":["M","F","F","M","F","M","F","F","M","F","M","F","F"], "Treatment":[1,0,0,1,1,1,0,0,0,1,1,1,0] } }

Example: ggplot2

ggplot webapp: 3 R-scripts ggplot-upload: Starts R session and reads a datafile from POST. Imports datafile to dataframe. Saves the session. Returns datafile variable info and session ID. ggplot-png: Decodes plot-config and Session ID from POST. Loads the appropriate R session. Draws the plot and saves in a www dir. Returns a link to the figure (or an error). ggplot-pdf Idem for PDF.

Javascript fragment plotconfig is the object that holds information about the current plot. The function drawplot encodes and posts it. function drawplot(){ Ext.getCmp( workspace ).load({ timeout: 60, //timeout for load is in seconds url:"../brew/ggplot-png", method: "POST", params: { "plotrequest" : plotconfig.tojson() }, callback: function(el,success,response) { Ext.getCmp( drawbutton ).enable(); plotresult = trydecode(response.responsetext); } }); }

Request Object: lme Request { } "x":"map_mpaa", "y":"map_rating", "colour":"map_mpaa", "facet":{}, "layers":{ "layer80667":{ "geom":"boxplot" }, "layer39359":{ "geom":"point", "position":"set_jitter" } }, "datafile":178032, "width":916, "height":270

Server Fragment (R) drawplot <- function(){ plotrequest <- fromjson(as.character(post$plotrequest)); sessionid <- plotrequest$sessionid; load(sessionid); plotconfig <- plotrequest$plotconfig; filename <- randomname(); png(paste("/var/www/ggplot2/plots/",filename,".png",sep="")); drawplot(plotconfig); dev.off(); cat("<img src="/ggplot2/",filename,".png",sep=""); }

Some Advice Use Firefox + Webdev toolbar + firebug for development. Design a protocol that makes sense semantically. Don t use R to generate Layout or HTML. This soon become unmanageble. Only computing at the server, do all layout stuff at the client.

Connecting your HTTPD to R RApache/brew: Module for Apache webserver + scripting package. New R session for every http request. Fast, good caching. Calling Rscript from php/cgi No need for extra plugins. Works on windows. Extra sensitive to code injection! Rserve: Keeps an R session alive. Requires additional Rserve client. If session gets messed up, you re screwed.

Catch errors To catch errors and return them to the user: drawplot <- function(){ //where actual stuff happens } printerror <- function(e){ print("oh no! An error occured:\n"); print(e$message); } trycatch(drawplot,error=printerror);

Time limits To limit the time of a session, start the R script with: settimelimit(elapsed=40); Be sure to reset the timer on the end of the script: settimelimit();

Images Format to display images: PNG, SVG, PDF, Flash. Bitmap or Vector Based? Browser support. File size.

Security Watch out for code injection! Parse user data safely. Don t let a user specify which function to run. If necessary, remove any weird characters from argument strings.

Graphical Interfaces There are many free and open-source javascript libraries that provide ready-to-use interfaces and widgets. Easily create Grids, Tabs, Windows, Drag/drop, Trees, Forms, Toolbars, etc with only a few lines of code. Framework Prototype/Scriptaculous Yahoo! User Interface Library (YUI) jquery Dojo Ext License MIT BSD GPL or MIT BSD GPL or Commercial

Thank you for your attention! Jeffrey Horner (2009). rapache: Web application development with R and Apache. http://biostat.mc.vanderbilt.edu/rapache/ Hadley Wickham (2009). ggplot2: An implementation of the Grammar of Graphics. http://cran.r-project.org/package=ggplot2 van Buuren S, Ooms JCL (2009). Stage line diagram: An age-conditional reference diagram for tracking development. Statistics in Medicine. w3schools: Full Web Building Tutorials - All Free.

Thank you for your attention! Get the slides at: http://www.stat.ucla.edu/~jeroen/ Contact: jeroenooms@gmail.com