Wednesday, September 7, 2016

Shiny, R and HTML: Merging Data Science and Web Development

Shiny, R and HTML: Merging Data Science and Web Development

With the advent of data science and the increased need to analyze and interpret vast amounts of data, the R language has become ever more popular. However, there's increasingly a need for a smooth interaction between statistical computing platforms and the web, given both 1) the need for a more interactive user interface in analyzing data, and 2) the increased role of the cloud in running such applications.

Statisticians and web developers have thus seemed an unlikely mix till now, but make no mistake that the interactions between these two groups will continue to increase as the need for web-based platforms becomes ever more popular in the world of data science. In this regard, the interaction of the R and Shiny platforms is quickly becoming a cornerstone of interaction between the world of data and the web.

In this tutorial, we'll look primarily at the commands used to build an application in Shiny --- both on the UI (user interface) side and the server side. While familiarity with the R programming language is invariably helpful in creating a Shiny app, expert knowledge is not necessary, and this example will cover the building of a simple statistical graph in Shiny, along with some basic commands illustrating how to customize the web page through HTML.

Installing and Loading Shiny Web Apps

To start off, we must first install the RStudio platform in order to create and run a Shiny Web App. RStudio can be downloaded from the RStudio website.

Once we've loaded the RStudio platform, we then create our new Shiny web application by selecting the New File option, and then the Shiny Web App… option.

creating a new Shiny web app

Upon doing that, we're presented with an interface that allows us to name our application (I've named it “OurFirstApp”, but feel free to come up with other creative names!), and we then select Multiple File (ui.R/server.R) as our application type:

Shiny web app interface

While we could select Single File (app.R), this literally just combines the ui.R and server.R scripts into one. I personally prefer to keep the two separate in order to keep the code less cluttered, but this is a matter of personal preference.

As a side note, there's also a web platform available on the Shinyapps site, which allows users to share their Shiny applications online, as well as use the rsconnect package to control such applications remotely from the R console. While the methodology for doing this is outside the scope of this article, I definitely intend on expanding this topic further in subsequent articles given interest.

In any case, once we have named our Shiny Web App and opened up the source code, we're presented with a template app that uses a dataset “Old Faithful Geyser Data” to generate a histogram. For the purposes of this tutorial, we'll be writing our own app and customizing it according to our needs.

Continue reading %Shiny, R and HTML: Merging Data Science and Web Development%


by Michael Grogan via SitePoint

No comments:

Post a Comment