styler
packagescale()
R Shiny is an R package that enables seamless creation of interactive web applications using exclusively R. This is quite the feat since R is very much not a web programming language like JavaScript. It allows for data scientists like us, who are much more comfortable creating scripts and analyses, to leverage their skills and make attractive, functional web apps to share with their collaborators and beyond.
Shiny is much easier to use thanks to its built-in shorthands for common web elements. A paragraph tab, used for normal text, can be types with p("Text")
instead of HTML’s clunkier <p>Text</p>
. This applies to even more complicated objects like buttons, sliders, and outputting plots and tables.
This chapter will bring you through the basics of constructing an app, and the nature of reactive programming. It is still R, it will still mostly feel like R, but Shiny is a veneer of utility that turns your average data scientist into a web developer fully equipped to impress any lab peer.
Before we get into the the nuts and bolts of Shiny’s usefulness, we should first outline the need for this library. A typical, static (meaning it is the same every time you visit it) webpage has three components:
1. HTML - hypertext markup language, the bones of the web page
2. CSS - cascading style sheets, the design and aesthetic portions
3. JavaScript - a programming language made for the web, used for making web pages interactive and adaptive.
Normally, these elements are create separately in different files, placed onto a web server, and delivered to the user when they load that web page. You’re probably with one or all three of these in one sense or another, and you can see how they work by opening up your browser’s console.
Dealing with all of those HTML tags (things that look like this: <p>Woa</p>
) is far too much work, so we can use Shiny to not only put together the bones of our website, we can easily customize the CSS and JavaScript elements as well, which will give our applications a fully configurable R-like feel for our users who are hungry for pretty data science and bioinformatics.
Getting start with Shiny is easy whether you’re on SCC or your own computer. Simple select a new project, choose new directory, and select the Shiny option as seen below.
This chapter has exercises! Woo! Launch R on your machine or on SCC or on both! Install Shiny using install.packages("shiny")
, then load with library(shiny)
. Follow along in these boxes!
Further reading:
- Parts of this chapter are adapted from Hadley Wickham’s Book on Shiny
- The Official R Shiny Cheat Sheet
- Further widgets for unique outputs: HTML Widgets