R Language Shiny Create an app


Example

Shiny is an R package developed by RStudio that allows the creation of web pages to interactively display the results of an analysis in R.

There are two simple ways to create a Shiny app:

  • in one .R file, or
  • in two files: ui.R and server.R.

A Shiny app is divided into two parts:

  • ui: A user interface script, controlling the layout and appearance of the application.
  • server: A server script which contains code to allow the application to react.

One file

library(shiny)

# Create the UI
ui <- shinyUI(fluidPage(
    # Application title
    titlePanel("Hello World!")
))

# Create the server function
server <- shinyServer(function(input, output){})

# Run the app
shinyApp(ui = ui, server = server)

Two files

Create ui.R file

library(shiny)

# Define UI for application
shinyUI(fluidPage(  
  # Application title
  titlePanel("Hello World!")
))

Create server.R file

library(shiny)

# Define server logic
shinyServer(function(input, output){})