What is Shiny?

Shiny is an R-based environment for building interactive web applications for data analysis and exploration. Since most JavaScript code is autogenerated by the environment, basic R knowledge is sufficient for developing Shiny apps. They can be deployed on local computers or web servers including custom and cloud-based servers (e.g. AWS, GCP, shinyapp.io service). The basic structure of a Shiny app is an app.R script containing the following components:

  1. User interface

     ui <- fluidPage()
  2. Server function

     server <- function(input, output) {}
  3. Statement to run shiny app

     shinyApp(ui = ui, server = server)

Alternatively, the ui and server functions can be organized in two script files, a ui.R and a server.R script, respectively.

Develop and test Shiny app locally

Open R and set session to parent directory (here myappdir) containing shiny script app.R, and the run it with the runApp() function. A sample app.R script for testing can be downloaded from here.

runApp("myappdir") # To show code in app, add argument: display.mode="showcase" 

This will open the app in a web browser.

Deploy on web server

This can be done on local or cloud systems. An easy solution is to get an account on shinyapps.io and then deploy Shiny apps there. For details, see here.


Example Shiny app

The following Shiny app is hosted on shinyapps.io and embedded into the markdown (or html) source of this page using the following iframe syntax:

<iframe src="https://tgirke.shinyapps.io/diamonds/" style="border: none; width: 880px; height: 900px"></iframe>

Learning Shiny

The Shiny section on the Rstudio site contains excellent tutorials. In addition, users may want to explore the example apps included in the shiny package. This can be done by loading the individual examples (see here) or saving the code to a user writable directory like this:

mydir <- system.file("examples", package="shiny")
file.copy(mydir, "my_shiny_test_dir", recursive=TRUE)
runApp("01_hello") # Runs first example app in directory 
dir() # Lists available Shiny examples (directories). 

Previous page.Previous Page                     Next Page Next page.