Sharing Your Shiny Apps

February 3, 2015
By

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

by Siddarth Ramesh
R Programmer, Revolution Analytics

A couple of months ago, I worked on a customer engagement involving Shiny. Shiny is a package created by RStudio that is intended to make plots dynamic and interactive. One advantage of Shiny is that an app would completely be written in R, without needing to know any other programming languages. Shiny is a powerful tool for creating an interactive interface for applications such as predictive analysis. In this post I’ll go over a higher level view of Shiny, and delve into one of its deepest features – the ease of sharing your app with the world.

For those of you who are not familiar with Shiny, I’ll briefly provide a description of the high level architecture. A Shiny application is comprised of two R files – a server and a user interface (UI) file. The UI file acts as an HTML interpreter – you can create your buttons, checkboxes, images, and other HTML widgets from here. The server file is where Shiny’s real magic happens. This is where you can make those buttons and checkboxes that you created in your UI actually do something. In other words, it is where R users can turn their app, using only R, into a dynamic visual masterpiece. If you type in runApp("appName") from your console window, with the Shiny app folder as your working directory of course, then you can see your output.

The following is a small Shiny App I made. Note that both the UI and the server.R files work in conjunction and must be in the same directory to create the final output:

UI Code

  Sid-1

Server Code

  Sid-2

With Shiny, you can completely customize your specifications for a plot and the plot will change right in front of you.

One of Shiny’s benefits lies in the ease with which Shiny apps can be shared. Originally, I thought that in order to host my Shiny app on the web, I would need to somehow procure a dedicated server and acquire a URL before I could even think about sharing it with the world. This is a complicated process, and I had a server and was figuring out how to get the URL when I discovered shinyapps.io

Shinyapps.io is a platform which allows you to share your Shiny applications online. In order to use Shinyapps.io, you would first have to install it with:

devtools::install_github('rstudio/shinyapps')

Depending on the type of operating system you have, Shinyapps.io has a few dependencies that need to be installed. Since I am a Windows user, I needed RTools and the devtools R package. Linux users need GCC, and Mac users need XCode Command Line Tools.

Instead of running the runApp("ShinyAppName") command which opens up your Shiny app locally on your machine, you would instead run deployApp("ShinyAppName"). The command “deployApp()” automatically syncs up to the Shinyapps.io server, and opens up the shinyapps.io website on your browser. If you have never used shinyapps.io, you must first set up an account. Creating an account is simple to do, and once you have a shinyapps.io account, your application from RStudio will become an instance on the shinyapps.io server with its own URL. At this point, your application is on the internet and can be viewed by anybody with access to it.

There are some advantages to using Shinyapps.io. One is that it negates the need for your own server, as you would be hosting it on the Shinyapps.io virtualized server. This saves you some money, and you would not have to worry about maintaining the server. If you are worried about security, you do not have to be because each shiny app is in a protected environment, each application is SSL encrypted, and user authentication is offered. One thing that R users who use R Markdown may notice is that the process of uploading a Shiny apps to shinyapps.io is fairly similar to uploading a Markdown file to Rpubs. 

This link following is the output of the simple Shiny application I had previously created, and hosted as an instance on shinyapps.io:

  Sid-3

Shiny is constantly being improved upon, and as aesthetically pleasing and smooth as it is right now, it is only getting more elegant as time goes by.  If you are interested in exploring the power and diversity of Shiny, check out this link below!

http://www.showmeshiny.com/

 

To leave a comment for the author, please follow the link and comment on their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)