Introduction to Shiny

STAT 220

Bastola

Introducing Shiny

  • A special R package for making your data interactive.
  • Turns your analyses into interactive web apps.

Create and Host Interactive Dashboards

  • Interactive Dashboards: Easily create dynamic dashboards in R. No web development skills required!
  • Hosting Made Easy: Develop in RStudio and host your apps seamlessly on the web using RStudio’s servers.
  • ShinyApps.io: Publish and share your interactive graphs and data analyses on ShinyApps.io, making your work accessible worldwide.
  • ShinyLive Integration: Utilize ShinyLive for enhanced real-time interactions without server setup, directly running R applications in the browser.

Engaging Data Visualizations

  • Interactive Visualizations: Shiny turns your static data into engaging experiences by allowing interactive graphs and tables.
  • Responsive and Live Updates: Shiny listens to user inputs, updating outputs automatically to reflect changes, enhancing user experience and engagement.
  • ShinyLive Features: Extend functionalities with ShinyLive, enabling more complex user interactions directly within web browsers, without the need for additional server resources.

Building Blocks of a Shiny App

  • Every Shiny app has two main parts:

    • User Interface (UI): What you see on the screen.
    • Server Function: The brain behind the scenes doing the calculations.
  • You combine these with shinyApp to make your interactive web app.

  • To tell RStudio it’s a Shiny app, add runtime: shiny to the top of your R Markdown file.

Useful Resources

Link here

Hello World

library(shiny)
ui <- fluidPage("Hello World!")
server <- function(input, output) {}
shinyApp(ui = ui, server = server)

Add more information

library(shiny)
ui <- fluidPage(
  titlePanel("Tracking Covid in Minnesota"),
  h1("Some nice header"),
  "elements1",
  "elements2",
  br(),
  "things1",
  strong("things2")
  )
server <- function(input, output) {}
shinyApp(ui = ui, server = server)

Add a layout

fluidPage(
  titlePanel("Tracking Covid in Minnesota"),
  sidebarLayout(sidebarPanel("our inputs will go here"),
                mainPanel("the results will go here"))
)

Tabset Panel Layout

ui <- fluidPage(
    titlePanel("My Tabbed App"),
    sidebarLayout(sidebarPanel("Inputs here"),
        mainPanel(tabsetPanel(
                tabPanel("Plot", plotOutput("plot")),
                tabPanel("Summary", verbatimTextOutput("summary")),
                tabPanel("Table", DTOutput("table")))))
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)

Using Shiny Themes

library(shiny)
library(shinythemes)

ui <- fluidPage(theme = shinytheme("flatly"), 
    titlePanel("Themed Shiny App"),
    sidebarLayout(
        sidebarPanel("Sidebar content"),
        mainPanel("Main content")
    )
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)

Input-Output Pairs

 Group Activity 1


  • Please clone the ca18-yourusername repository from Github
  • Please do the problem 1 in the class activity for today

30:00