Introduction to Shiny BUILDIN G W EB AP P LICATION S W ITH S H IN - - PowerPoint PPT Presentation

introduction to shiny
SMART_READER_LITE
LIVE PREVIEW

Introduction to Shiny BUILDIN G W EB AP P LICATION S W ITH S H IN - - PowerPoint PPT Presentation

Introduction to Shiny BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R Ramnath Vaidyanathan VP of Product Research Introduction to Shiny BUILDING WEB APPLICATIONS WITH SHINY IN R What is a web app? Updates based on user input/interaction


slide-1
SLIDE 1

Introduction to Shiny

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

Ramnath Vaidyanathan

VP of Product Research

slide-2
SLIDE 2

BUILDING WEB APPLICATIONS WITH SHINY IN R

Introduction to Shiny

slide-3
SLIDE 3

BUILDING WEB APPLICATIONS WITH SHINY IN R

What is a web app?

Updates based on user input/interaction Made up of UI & server

slide-4
SLIDE 4

BUILDING WEB APPLICATIONS WITH SHINY IN R

What is a web app?

Displays paths to the White House for different presidential candidates.

slide-5
SLIDE 5

BUILDING WEB APPLICATIONS WITH SHINY IN R

What is a web app?

DataCamp mobile app

slide-6
SLIDE 6

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

slide-7
SLIDE 7

BUILDING WEB APPLICATIONS WITH SHINY IN R

What is Shiny?

slide-8
SLIDE 8

BUILDING WEB APPLICATIONS WITH SHINY IN R

Why should data scientists build web apps?

slide-9
SLIDE 9

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 )

slide-10
SLIDE 10

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 clusers', 3), plotly::plotlyOutput('kmeans_plot') ) server <- function(input, output, session){

  • utput$kmeans_plot <- plotly::renderPlotly({

plot_kmeans(iris, input$x, input$y, input$nb_clusters) }) } shinyApp(ui = ui, server = server)

slide-11
SLIDE 11

BUILDING WEB APPLICATIONS WITH SHINY IN R

Why should data scientists build web apps?

slide-12
SLIDE 12

Let's practice!

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

slide-13
SLIDE 13

Build a "Hello, world" Shiny app

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

Kaelen Medeiros

Data Scientist

slide-14
SLIDE 14

BUILDING WEB APPLICATIONS WITH SHINY IN R

Parts of a Shiny app

library(shiny) ui <- fluidPage() server <- function(input,

  • utput,

session) { } shinyApp(ui = ui, server = server)

Load shiny Create the UI with a HTML function Dene a custom function to create the server Run the app

slide-15
SLIDE 15

BUILDING WEB APPLICATIONS WITH SHINY IN R

Hello, world!!!

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

slide-16
SLIDE 16

BUILDING WEB APPLICATIONS WITH SHINY IN R

Ask a question (with an input!)

ui <- fluidPage( textInput("name", "Enter a name:"), textOutput("q") ) server <- function(input, output) {

  • utput$q <- renderText({

paste("Do you prefer dogs

  • r cats,",

input$name, "?") }) }

slide-17
SLIDE 17

Let's practice!

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

slide-18
SLIDE 18

Build a babynames explorer Shiny app

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R

Ramnath Vaidyanathan

VP of Product Research

slide-19
SLIDE 19

BUILDING WEB APPLICATIONS WITH SHINY IN R

Sketch your app

slide-20
SLIDE 20

BUILDING WEB APPLICATIONS WITH SHINY IN R

Add inputs (UI)

ui <- fluidPage( titlePanel("Baby Name Explorer"), textInput('name', 'Enter Name', 'David') ) server <- function(input, output, session){ } shinyApp(ui = ui, server = server)

slide-21
SLIDE 21

BUILDING WEB APPLICATIONS WITH SHINY IN R

Add outputs (UI/server)

ui <- fluidPage( titlePanel("Baby Name Explorer"), textInput('name', 'Enter Name', 'David'), plotOutput('trend') ) server <- function(input, output, session){

  • utput$trend <- renderPlot({

ggplot() }) } shinyApp(ui = ui, server = server)

slide-22
SLIDE 22

BUILDING WEB APPLICATIONS WITH SHINY IN R

Add outputs (UI/server)

slide-23
SLIDE 23

BUILDING WEB APPLICATIONS WITH SHINY IN R

Update layout (UI)

ui <- fluidPage( titlePanel("Baby Name Explorer"), sidebarLayout( sidebarPanel( textInput('name', 'Enter Name', 'David') ), mainPanel( plotOutput('trend') ) ) ) server <- function(input, output, session){

  • utput$trend <- renderPlot({ggplot()})

}

slide-24
SLIDE 24

BUILDING WEB APPLICATIONS WITH SHINY IN R

Update layout (UI)

slide-25
SLIDE 25

BUILDING WEB APPLICATIONS WITH SHINY IN R

Update output (server)

ui <- fluidPage( ... ) server <- function(input, output, session){

  • utput$trend <- renderPlot({

data_name <- subset( babynames, name == input$name ) ggplot(data_name) + geom_line( aes(x = year, y = prop, color = sex) ) }) }

slide-26
SLIDE 26

Let's practice!

BUILDIN G W EB AP P LICATION S W ITH S H IN Y IN R