Exploring Titanic Survival Demographics with Shiny R

Regis O'Connor
December 27, 2016

An Interactive Tool to Explore the Titanic Survival Data

  • Objective: Use Shiny R to enhance data exploration

  • Technique: Combine a static chart with dynamic data sorting to stimulate analytical imagination. Created in RStudio version 1.0.44, with R version 3.3.2. Uses shiny, DT and vcd packages as well as Titanic dataset.

  • Comments: Shinyio does not deploy the code completely and I can't figure it out. Therefore, the shinyio link will look incomplete.

  • Next Steps: Develop strategy for building predictive models

ui.R

library(shiny)
shinyUI(fluidPage(
  titlePanel("Titanic Passengers and Crew - Who Lived and Died?"),
  sidebarLayout(
    sidebarPanel(
      conditionalPanel(
        'inputdataset=="Titanic"',
        helpText('In the Data tab, click the column header to sort a column. Click the Plot tab to see the overall survival chart.')
      )
    ),
  mainPanel(
    tabsetPanel(
      tabPanel("Data", DT::dataTableOutput('Table1')),
      tabPanel("Plot", plotOutput("Plot1"))
    )))
))

server.R

library(shiny)
library(DT)
library(vcd)
shinyServer(function(input, output){
  #columns have colors attached cuz of CSS
  output$Table1 <- DT::renderDataTable({
    DT::datatable(as.data.frame(Titanic), options = list(orderClasses = TRUE,
                  lengthMenu = c(4, 8, 16, 32), pageLength = 8))
  }) 
  output$Plot1 <- renderPlot({
    strucplot(Titanic, spacing = spacing_highlighting, 
              labeling=labeling_left, 
              gp = gpar(fill = c("black","green")))
  })  
})

Summary of Titanic Data

            Sex      Male     Female    
            Survived   No Yes     No Yes
Class Age                               
1st   Child             0   5      0   1
      Adult           118  57      4 140
2nd   Child             0  11      0  13
      Adult           154  14     13  80
3rd   Child            35  13     17  14
      Adult           387  75     89  76
Crew  Child             0   0      0   0
      Adult           670 192      3  20

plot of chunk unnamed-chunk-4