Skip to content

Commit

Permalink
Deploy apps for tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Apr 25, 2023
1 parent f042d33 commit a072bba
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 0 deletions.
80 changes: 80 additions & 0 deletions 500-movie-browser/app.R
@@ -0,0 +1,80 @@
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#

library(shiny)
library(tidyverse)

load("movies.RData")

# Define UI for application that draws a histogram
ui <- fluidPage(
titlePanel("Movie browser, 1970 to 2014", windowTitle = "Movies"),
sidebarLayout(
sidebarPanel(
checkboxGroupInput(
inputId = "type",
label = "Title type:",
choices = levels(movies$title_type),
selected = "Feature Film"
)
),
mainPanel(
tabsetPanel(
type = "tabs",
tabPanel("Plot", plotOutput("plot")),
tabPanel("Summary", tableOutput("summary")),
tabPanel("Data", DT::dataTableOutput("data")),
tabPanel(
"Reference", tags$p(
"There data were obtained from",
tags$a("IMDB", href = "http://www.imdb.com/"), "and",
tags$a("Rotten Tomatoes", href = "https://www.rottentomatoes.com/"), "."
),
tags$p("The data represent ", nrow(movies), "randomly sampled movies released between 1972 to 2014 in the Unites States.")
)
)
)
)
)

# Define server logic required to draw a histogram
server <- function(input, output) {

load("movies.RData")

movies_subset <- reactive({
movies %>%
filter(title_type %in% input$type)
})

output$plot <- renderPlot({
ggplot(movies_subset(), aes(x = critics_score, y = audience_score, color = mpaa_rating)) +
geom_point()
})
output$summary <- renderTable(
{
movies_subset() %>%
group_by(mpaa_rating) %>%
summarise(
mean_as = mean(audience_score), sd_as = sd(audience_score),
mean_cs = mean(critics_score), sd_cs = sd(critics_score),
n = n(), cor = cor(audience_score, critics_score)
)
},
digits = 3
)
output$data <- DT::renderDataTable({
movies_subset() %>%
DT::datatable(options = list(pageLength = 10), rownames = FALSE)
})

}

# Run the application
shinyApp(ui = ui, server = server)
Binary file added 500-movie-browser/movies.RData
Binary file not shown.
90 changes: 90 additions & 0 deletions 501-movie-browser-nav/app.R
@@ -0,0 +1,90 @@
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#

library(shiny)
library(tidyverse)

load("movies.RData")

# Define UI for application that draws a histogram
ui <- fluidPage(
titlePanel("Movie browser, 1970 to 2014", windowTitle = "Movies"),
sidebarLayout(
sidebarPanel(
checkboxGroupInput(
inputId = "type",
label = "Title type:",
choices = levels(movies$title_type),
selected = "Feature Film"
)
),
mainPanel(
navlistPanel(
tabPanel("Plot", plotOutput("plot2")),
tabPanel("Summary", tableOutput("summary2")),
tabPanel("Data", DT::dataTableOutput("data2")),
tabPanel(
"Reference",
tags$p(
"There data were obtained from",
tags$a("IMDB", href = "http://www.imdb.com/"), "and",
tags$a("Rotten Tomatoes", href = "https://www.rottentomatoes.com/"), "."
),
tags$p("The data represent", nrow(movies), "randomly sampled movies released between 1972 to 2014 in the United States.")
)
)
)
)
)

# Define server logic required to draw a histogram
server <- function(input, output) {

file <- "https://github.com/rstudio-education/shiny-course/raw/main/movies.RData"
destfile <- "movies.RData"

download.file(file, destfile)

load("movies.RData")

movies_subset <- reactive({
movies %>%
filter(title_type %in% input$type)
})

movies_subset2 <- reactive({
movies %>%
filter(title_type %in% input$type)
})

output$plot2 <- renderPlot({
ggplot(movies_subset(), aes(x = critics_score, y = audience_score, color = mpaa_rating)) +
geom_point()
})
output$summary2 <- renderTable(
{
movies_subset2() %>%
group_by(mpaa_rating) %>%
summarise(
mean_as = mean(audience_score), sd_as = sd(audience_score),
mean_cs = mean(critics_score), sd_cs = sd(critics_score),
n = n(), cor = cor(audience_score, critics_score)
)
},
digits = 3
)
output$data2 <- DT::renderDataTable({
movies_subset2() %>%
DT::datatable(options = list(pageLength = 10), rownames = FALSE)
})

}

# Run the application
shinyApp(ui = ui, server = server)
Binary file added 501-movie-browser-nav/movies.RData
Binary file not shown.
55 changes: 55 additions & 0 deletions 502-random-number/app.R
@@ -0,0 +1,55 @@
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#

library(shiny)

# Define UI for the app
ui <- fluidPage(
titlePanel("Random number generator"),
sidebarLayout(
sidebarPanel(
selectInput(
"digit_type", "Number of digits:",
c("any", "selected")
),
conditionalPanel(
condition = "input.digit_type == 'selected'",
sliderInput("digit_count", "How many digits?",
min = 1, max = 10, value = 4
)
),
actionButton("go", "Generate new random number"),
width = 5
),
mainPanel(
br(),
"Your random number is",
h4(textOutput("random_number")),
width = 7
)
)
)

# Define server logic required to draw a histogram
server <- function(input, output) {

output$random_number <- renderText({
input$go
raw <- runif(1)
digits <- if (input$digit_type == "any") {
sample(1:10, size = 1)
} else {
input$digit_count
}
round(raw * 10^digits)
})
}

# Run the application
shinyApp(ui = ui, server = server)
26 changes: 26 additions & 0 deletions 503-server-function/app.R
@@ -0,0 +1,26 @@
# Hello Shiny: Server function
# Shiny app
# Practice: Matching inputs and outputs

library(shiny)

ui <- fluidPage(

textInput(
inputId = "custom_text",
label = "Input some text here:"
),

strong("Text is shown below:"),

textOutput(outputId = "user_text")

)

server <- function(input, output, session){

output$user_text <- renderText({ input$custom_text })

}

shinyApp(ui = ui, server = server)

0 comments on commit a072bba

Please sign in to comment.