DDP: Course Project - Shiny Application and Reproducible Pitch

Cecilia Cruz-Ram, MD DPCOM

10/28/2020

Introduction

This Shiny application is created to easily show the number of COVID-19 case status per region. The source of the data is PH COVID-19 Case Database.

I used the tutorial of Dean Attali’s Building Shiny apps - an interactive tutorial to create this application.

The link to the shiny server is COVID19.

Overview

The dataset is based on the PH COVID-19 Case Database. You can see the cases based on the parameters chosen (age, patient status, region).

Here is a snapshot of the app.

R Code: UI

library(shiny)
library(ggplot2)
library(dplyr)

covid <- read.csv("COVID-19PH.csv", stringsAsFactors = FALSE)
ui <- fluidPage(
  titlePanel("COVID-19 Cases in the Philippines"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("ageInput", "Age", 0, 100, c(20, 40)),
      radioButtons("statusInput", "Status",
                choices = c("Recovered", "Admitted", "Dead"),
                selected = "Recovered"),
      uiOutput("regionOutput")
  ),
  mainPanel(
    plotOutput("caseplot"),
    br(), br(),
    tableOutput("results")
    )
  )
)

R Code: Server

server <- function(input, output) {
  output$regionOutput <- renderUI({
    selectInput("regionInput", "Region",
                sort(unique(covid$Region)),
                selected = "NCR")
  })
  filtered <- reactive({
    if (is.null(input$regionInput)) {
      return(NULL)
    }    
    covid %>%
    filter(Age >= input$ageInput[1],
           Age <= input$ageInput[2],
           Status == input$statusInput,
           Region == input$regionInput
    )
  })
  output$caseplot <- renderPlot({
    if (is.null(filtered())) {
      return()
    }
    ggplot(filtered(), aes(Age)) + 
      geom_histogram(fill = "darkgreen", alpha = 0.5, position = "dodge")
  })
  output$results <- renderTable({
    filtered()
  })
}
shinyApp(ui = ui, server = server)