welcome to the course building web applications in r with
play

Welcome to the course! Building Web Applications in R with Shiny - PowerPoint PPT Presentation

BUILDING WEB APPLICATIONS IN R WITH SHINY Welcome to the course! Building Web Applications in R with Shiny Building Web Applications in R with Shiny Background You are familiar with R as a programming language. You are familiar with


  1. BUILDING WEB APPLICATIONS IN R WITH SHINY Welcome to the course!

  2. Building Web Applications in R with Shiny

  3. Building Web Applications in R with Shiny Background ● You are familiar with R as a programming language. ● You are familiar with the Tidyverse, specifically ggplot2 and dplyr.

  4. Building Web Applications in R with Shiny Help www.rstudio.com/ shiny.rstudio.com/ resources/cheatsheets/

  5. Building Web Applications in R with Shiny Tips ● Always run the entire script, not just up to the point where you’re developing code. ● Sometimes the best way to see what’s wrong is to run the app and review the error. ● Watch out for commas!

  6. Building Web Applications in R with Shiny Anatomy of a Shiny app library(shiny) User interface controls the layout and ui <- fluidPage() appearance of app Server function server <- function(input, output) {} contains instructions needed to build app shinyApp() shinyApp(ui = ui, server = server) Creates the Shiny app object

  7. Building Web Applications in R with Shiny Data Let’s build a simple movie browser app! movies.Rdata Data from IMDB and Rotten Tomatoes on random sample of 651 movies released in the US between 1970 and 2014

  8. Building Web Applications in R with Shiny Revisit library(shiny) Data used for this app library("movies.Rdata") ui <- fluidPage() server <- function(input, output) {} shinyApp(ui = ui, server = server)

  9. BUILDING WEB APPLICATIONS IN R WITH SHINY Let’s practice!

  10. BUILDING WEB APPLICATIONS IN R WITH SHINY User interface

  11. Building Web Applications in R with Shiny Anatomy of a Shiny app library(shiny) library("movies.Rdata") User interface ui <- fluidPage() - Inputs defined and laid out - Outputs laid out Server function - Outputs calculated server <- function(input, output) {} - Any other calculations needed for outputs are performed shinyApp(ui = ui, server = server)

  12. Building Web Applications in R with Shiny server ggplot(data = movies, aes_string(x = input$x, y = input$y)) + geom_point() ui

  13. Building Web Applications in R with Shiny

  14. Building Web Applications in R with Shiny # Define UI for application that plots features of movies ui <- fluidPage( # Sidebar layout with a input and output definitions sidebarLayout( # Inputs: Select variables to plot sidebarPanel( # Select variable for y-axis selectInput(inputId = "y", label = "Y-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "audience_score"), # Select variable for x-axis selectInput(inputId = "x", label = "X-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "critics_score") ), # Output: Show scatterplot mainPanel( plotOutput(outputId = "scatterplot") ) ) )

  15. Building Web Applications in R with Shiny # Define UI for application that plots features of movies Create fluid page layout ui <- fluidPage( # Sidebar layout with a input and output definitions sidebarLayout( # Inputs: Select variables to plot sidebarPanel( # Select variable for y-axis selectInput(inputId = "y", label = "Y-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "audience_score"), # Select variable for x-axis selectInput(inputId = "x", label = "X-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "critics_score") ), # Output: Show scatterplot mainPanel( plotOutput(outputId = "scatterplot") ) ) )

  16. Building Web Applications in R with Shiny # Define UI for application that plots features of movies ui <- fluidPage( Create a layout with a # Sidebar layout with a input and output definitions sidebarLayout( sidebar and main area # Inputs: Select variables to plot sidebarPanel( # Select variable for y-axis selectInput(inputId = "y", label = "Y-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "audience_score"), # Select variable for x-axis selectInput(inputId = "x", label = "X-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "critics_score") ), # Output: Show scatterplot mainPanel( plotOutput(outputId = "scatterplot") ) ) )

  17. Building Web Applications in R with Shiny sidebarPanel mainPanel

  18. Building Web Applications in R with Shiny # Define UI for application that plots features of movies ui <- fluidPage( # Sidebar layout with a input and output definitions sidebarLayout( # Inputs: Select variables to plot Create a sidebar panel containing sidebarPanel( input controls # Select variable for y-axis selectInput(inputId = "y", label = "Y-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "audience_score"), # Select variable for x-axis selectInput(inputId = "x", label = "X-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "critics_score") ), # Output: Show scatterplot mainPanel( plotOutput(outputId = "scatterplot") ) ) )

  19. Building Web Applications in R with Shiny # Define UI for application that plots features of movies ui <- fluidPage( # Sidebar layout with a input and output definitions sidebarLayout( # Inputs: Select variables to plot sidebarPanel( # Select variable for y-axis selectInput(inputId = "y", label = "Y-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "audience_score"), # Select variable for x-axis selectInput(inputId = "x", label = "X-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "critics_score") ), # Output: Show scatterplot mainPanel( plotOutput(outputId = "scatterplot") ) ) )

  20. Building Web Applications in R with Shiny # Define UI for application that plots features of movies ui <- fluidPage( # Sidebar layout with a input and output definitions sidebarLayout( # Inputs: Select variables to plot sidebarPanel( # Select variable for y-axis selectInput(inputId = "y", label = "Y-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "audience_score"), # Select variable for x-axis selectInput(inputId = "x", label = "X-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "critics_score") ), # Output: Show scatterplot mainPanel( plotOutput(outputId = "scatterplot") ) ) )

  21. Building Web Applications in R with Shiny # Define UI for application that plots features of movies ui <- fluidPage( # Sidebar layout with a input and output definitions sidebarLayout( # Inputs: Select variables to plot sidebarPanel( # Select variable for y-axis selectInput(inputId = "y", label = "Y-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "audience_score"), # Select variable for x-axis selectInput(inputId = "x", label = "X-axis:", choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), selected = "critics_score") ), # Output: Show scatterplot Create a main panel containing mainPanel( output elements that get created plotOutput(outputId = "scatterplot") in the server function ) ) )

  22. BUILDING WEB APPLICATIONS IN R WITH SHINY Let's practice!

  23. BUILDING WEB APPLICATIONS IN R WITH SHINY Server function

  24. Building Web Applications in R with Shiny

  25. Building Web Applications in R with Shiny # Define server function required to create the scatterplot server <- function(input, output) { # Create scatterplot object the plotOutput function is expecting output$scatterplot <- renderPlot({ ggplot(data = movies, aes_string(x = input$x, y = input$y)) + geom_point() }) }

  26. Building Web Applications in R with Shiny # Define server function required to create the scatterplot Contains instructions server <- function(input, output) { needed to build app # Create the scatterplot object the plotOutput function is expecting output$scatterplot <- renderPlot({ ggplot(data = movies, aes_string(x = input$x, y = input$y)) + geom_point() }) }

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend