Introduction to Shiny

Building Web Applications with Shiny in R

Ramnath Vaidyanathan

VP of Product Research

Introduction to Shiny

Shiny web app of wait times for Old Faithful geyser to explode, with number of histogram bins interactively adjustable

Building Web Applications with Shiny in R

What is a web app?

  • Updates based on user input/interaction
  • Made up of UI & server
Building Web Applications with Shiny in R

What is a web app?

NY Times "Paths to the White House" web app gif

  • Displays paths to the White House for different presidential candidates.
Building Web Applications with Shiny in R

What is a web app?

  • DataCamp mobile app

A gif of the DataCamp mobile app, displaying an example of a practice question.

Building Web Applications with Shiny in R

How does a web app work?

A web app is a thing that updates based on user input/interaction Diagram showing how clients and servers are connected to power web apps on the internet

Building Web Applications with Shiny in R

What is Shiny?

What is shiny diagram, displaying how server code and the UI interface are separate but work together to create an app

Building Web Applications with Shiny in R

Why should data scientists build web apps?

Iris dataset clustered by sepal.length and sepal.width, creating 3 distinct clusters

Building Web Applications with Shiny in R

Why should data scientists build web apps?

plot_kmeans(
  data = iris, 
  x = 'Sepal.Length', 
  y = 'Sepal.Width', 
  nb_clusters = 3
)

Iris dataset clustered by sepal.length and sepal.width, creating 3 distinct clusters

Building Web Applications with Shiny in R

Why should data scientists build web apps?

library(shiny)
ui <- fluidPage(
  h1('K-Means Clustering App'),
  selectInput('x', 'Select x', names(iris), 'Sepal.Length'),
  selectInput('y', 'Select y', names(iris), 'Sepal.Width'),
  numericInput('nb_clusters', 'Select number of clusters', 3),
  plotly::plotlyOutput('kmeans_plot')
)

server <- function(input, output, session){
  output$kmeans_plot <- plotly::renderPlotly({
    plot_kmeans(iris, input$x, input$y, input$nb_clusters)
  })
}

shinyApp(ui = ui, server = server)
Building Web Applications with Shiny in R

Why should data scientists build web apps?

web app that does K-means clustering of Iris dataset

Building Web Applications with Shiny in R

Let's practice!

Building Web Applications with Shiny in R

Preparing Video For Download...