Skip to content

Instantly share code, notes, and snippets.

@tommyhuang1
Last active February 5, 2017 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommyhuang1/393d1a8f9dc2f584c1096e172ba3453d to your computer and use it in GitHub Desktop.
Save tommyhuang1/393d1a8f9dc2f584c1096e172ba3453d to your computer and use it in GitHub Desktop.
R shiny
library(tidyr)
library(dplyr)
data<-read.csv("./data/UPdatedNYCLeadingCauseData.csv",stringsAsFactors = F)
HealthData<-filter(data,Leading.Cause=="All Other Causes", Year == '2007', Sex == 'F')
#Heart Disease Health Indicators data
HD1<-gather(HealthData,key="MortalityType",value="Mortality",c(35,37,39,41)) #Mortality
HD1<-HD1[,c(4,40,41)]
HD1[HD1$MortalityType=='HeartDiseaseMortality',]$MortalityType<-'Heart Disease Mortality'
HD1[HD1$MortalityType=='CerebrovascularDiseaseStrokeMortality',]$MortalityType<-'Cerebrovascular Disease Stroke Mortality'
HD1[HD1$MortalityType=='CoronaryHeartDiseaseMortality',]$MortalityType<-'Coronary Heart Disease Mortality'
HD1[HD1$MortalityType=='CongestiveHeartFailureMortality',]$MortalityType<-'Congestive Heart Failure Mortality'
HD2<-gather(HealthData,key="MortalityType",value="Mortality",c(36,38,40,42)) #hospitalizations
HD2<-HD2[,c(4,40,41)]
HD2[HD2$MortalityType=='HeartDiseaseHospitalizations',]$MortalityType<-'Heart Disease Hospitalizations'
HD2[HD2$MortalityType=='CerebrovascularDiseaseStrokeHospitalizations',]$MortalityType<-'Cerebrovascular Disease Stroke Hospitalizations'
HD2[HD2$MortalityType=='CoronaryHeartDiseaseHospitalizations',]$MortalityType<-'Coronary Heart Disease Hospitalizations'
HD2[HD2$MortalityType=='CongestiveHeartFailureHospitalizations',]$MortalityType<-'Congestive Heart Failure Hospitalizations'
#Injury-Related Indicators
IR1<-gather(HealthData,key="MortalityType",value="Mortality",c(12,13))
IR1<-IR1[,c(4,42,43)]
IR1[IR1$MortalityType=='MotorVehicleMortality',]$MortalityType<-'Motor Vehicle Mortality'
IR1[IR1$MortalityType=="UnintentionalInjuryMortality",]$MortalityType<-"Unintentional Injury Mortality"
IR2<-gather(HealthData,key="MortalityType",value="Mortality",c(14,15,16))
IR2<-IR2[,c(4,41,42)]
IR2[IR2$MortalityType=="UnintentionalInjuryHospitalizations",]$MortalityType<-"Unintentional Injury Hospitalizations"
IR2[IR2$MortalityType=="PoisoningHospitalizations",]$MortalityType<-"Poisoning Hospitalizations"
IR2[IR2$MortalityType=="FallHospitalizations",]$MortalityType<-"Fall Hospitalizations Aged 65+"
#Respiratory Disease Indicators
RD1<-gather(HealthData,key="MortalityType",value="Mortality",19)
RD1<-RD1[,c(4,43,44)]
RD1$MortalityType<-"Chronic Lower Respiratory Disease Mortality"
RD2<-gather(HealthData,key="MortalityType",value="Mortality",c(17,18,20))
RD2<-RD2[,c(4,41,42)]
RD2[RD2$MortalityType=="AsthmaHospitalizations",]$MortalityType<-"Asthma Hospitalizations"
RD2[RD2$MortalityType=="AsthmaHospitalizationsBelow17",]$MortalityType<-"Asthma Hospitalizations Aged Below 17"
RD2[RD2$MortalityType=="ChronicLowerRespiratoryDiseaseHospitalizations",]$MortalityType<-"Chronic Lower Respiratory Disease Hospitalizations"
#Substance Abuse and Mental Health-Related Indicators
SAM1<-gather(HealthData,key="MortalityType",value="Mortality",34)
SAM1<-SAM1[,c(4,43,44)]
SAM1$MortalityType<-"Suicide Mortality"
SAM2<-gather(HealthData,key="MortalityType",value="Mortality",33)
SAM2<-SAM2[,c(4,43,44)]
SAM2$MortalityType<-"Drug Related Hospitalizations"
#Diabetes Indicators
DI1<-gather(HealthData,key="MortalityType",value="Mortality",21)
DI1<-DI1[,c(4,43,44)]
DI1$MortalityType<-"Diabetes Mortality"
DI2<-gather(HealthData,key="MortalityType",value="Mortality",22:25)
DI2<-DI2[,c(4,40,41)]
DI2[DI2$MortalityType=="DiabetesAnyDiagnosisHospitalizations",]$MortalityType<-"Diabetes Any Diagnosis Hospitalizations"
DI2[DI2$MortalityType=="DiabetesShortTermComplicationsHospitalizations",]$MortalityType<-"Diabetes Short Term Complications Hospitalizations 6-17"
DI2[DI2$MortalityType=="DiabetesPrimaryDiagnosisHospitalizations",]$MortalityType<-"Diabetes Primary Diagnosis Hospitalizations"
DI2[DI2$MortalityType=="DiabetesShortTermComplicationsHospitalizations18Up",]$MortalityType<-"Diabetes Short Term Complications Hospitalizations 18+"
#Cancer Indicators
CI1<-gather(HealthData,key="MortalityType",value="Mortality",c(26,28,30,32))
CI1<-CI1[,c(4,40,41)]
CI1[CI1$MortalityType=="LungCancerIncidence",]$MortalityType<-"Lung Cancer Incidence"
CI1[CI1$MortalityType=="ColorectalCancerIncidence",]$MortalityType<-"Colorectal Cancer Incidence"
CI1[CI1$MortalityType=="CervicalCancerIncidence",]$MortalityType<-"Cervical Cancer Incidence"
CI1[CI1$MortalityType=="FemaleLateStageBreastCancerIncidence",]$MortalityType<-"Female Late Stage Breast Cancer Incidence"
CI2<-gather(HealthData,key="MortalityType",value="Mortality",c(27,29,31))
CI2<-CI2[,c(4,41,42)]
CI2[CI2$MortalityType=="ColorectalCancerMortality",]$MortalityType<-"Colorectal Cancer Mortality"
CI2[CI2$MortalityType=="FemaleBreastCancerMortality",]$MortalityType<-"Female Breast Cancer Mortality"
CI2[CI2$MortalityType=="CervixUteriCancerMortality",]$MortalityType<-"Cervix Uteri Cancer Mortality"
#Birth-Related Indicators
BI<-gather(HealthData,key="MortalityType",value="Mortality",11)
BI<-BI[,c(4,43,44)]
BI$MortalityType<-"Infant Mortality"
library(shiny)
library(ggplot2)
library(dplyr)
library(dygraphs)
library(googleVis)
library(ggvis)
shinyServer(function(input, output){
#Trend line for the total death for all years
GroupByYear<-reactive({
data %>% group_by(Year) %>% summarise(TotalDeath = sum(Deaths,na.rm=TRUE))
})
output$Trendline<-renderDygraph({
dygraph(GroupByYear(),width = 900, main = "2007 - 2014 Death Trend",xlab = "Year",ylab = "Total Death") %>%
dyRangeSelector(dateWindow = c("2006", "2016"))
})
#Trend line for the total death by sex for all years
output$TrendlineBySex<-renderPlot({
data %>% group_by(Year,Sex) %>% summarise(Total = sum(as.numeric(Deaths))) %>%
ggplot(.,aes(Year,Total)) + geom_line(aes(color = Sex)) + ylab('Total Death') + facet_wrap(~Sex)
})
#Trend line for the death by leading cause
GroupByYearLeadingCause<-reactive({
data %>% group_by(Year,Leading.Cause) %>% summarise(Total_Death = sum(as.numeric(Deaths),na.rm=TRUE))
})
output$TrendByLeadingCause<-renderPlot({
ggplot(GroupByYearLeadingCause()[GroupByYearLeadingCause()$Leading.Cause%in%input$Leading.Cause,],aes(Year,Total_Death)) +
geom_point() +
geom_line(aes(color = Leading.Cause)) +
ylab('Total Death') +
ggtitle('2007-2014 Death Trend by Leading Cause') +
theme(plot.title = element_text(hjust = 0.5)) +
guides(fill=guide_legend(title = "Leading Cause")) +
theme(plot.title = element_text(size = 15, face = "bold"))
})
#Barchart for death by leading cause
SelectedSex<-reactive({
if(input$Sex5=='All'){
return (data %>% group_by(Year,Leading.Cause) %>% filter(Leading.Cause == input$Leading.Cause1)%>%
summarise(TotalDeath = sum(as.numeric(Deaths),na.rm=TRUE))
)
}else{
return (data %>% group_by(Year,Sex,Leading.Cause) %>% filter(Leading.Cause == input$Leading.Cause1,Sex == input$Sex5)%>%
summarise(TotalDeath = sum(as.numeric(Deaths),na.rm=TRUE))
)
}
})
plot_df1 <- reactive({
if (input$Sex5 == "All"){
return ('All')
}else if(input$Sex5 == 'M'){
return ('Male')
}else{
return ('Female')
}
})
output$DeathBySexLeadingCause<-renderPlot({
ggplot(SelectedSex(),aes(factor(Year),TotalDeath)) +
geom_bar(stat="identity",fill ='blue4') + xlab("Year") + ylab("Total Death") +
ggtitle(paste("Death By Leading Cause for",plot_df1(),sep=' ')) + theme(plot.title = element_text(hjust = 0.5)) + theme(plot.title = element_text(size = 15, face = "bold"))
})
#Trend line for death by race ethnicity and Leading causes
output$TrendByLeadingCauseAndRace<-renderPlot({
data %>% group_by(Race_Ethnicity,Leading.Cause,Year) %>% summarise(TotalDeath = sum(as.numeric(Deaths),na.rm=TRUE)) %>% filter(Race_Ethnicity %in% input$RaceSelection,Leading.Cause==input$LeadingCauseType10) %>%
ggplot(aes(Year,TotalDeath)) +
geom_point() +
geom_line(aes(color = Race_Ethnicity)) +
ylab('Total Death') +
ggtitle('2007-2014 Death Trend by Leading Cause and Race')+
theme(plot.title = element_text(hjust = 0.5,size = 15, face = "bold")) +
guides(fill=guide_legend(title = "Leading Cause"))
})
#Trend line for the death by race ethnicity
output$TrendLineByRaceEthnicity<-renderPlot({
g<-group_by(data,Year,Race_Ethnicity)
s<-summarise(g,Total_Death = sum(as.numeric(Deaths),na.rm=TRUE))
ggplot(s[s$Race_Ethnicity%in%input$Race_Ethnicity,],aes(Year,Total_Death)) + geom_point() +
geom_line(aes(color = Race_Ethnicity)) + ylab('Total Death') +
ggtitle('2007-2014 Death Trend') + theme(plot.title = element_text(hjust = 0.5)) +
guides(fill=guide_legend(title = "Race Ethnicity")) + theme(plot.title = element_text(size = 15, face = "bold"))
})
#barchart by year for total death by year, option selection for Sex
output$DeathBySex<-renderGvis({
data$Year <- as.factor(data$Year)
k<-group_by(data,Year,Sex)
summary<-summarise(k[k$Sex==input$Sex,],TotalDeath = sum(Deaths,na.rm=TRUE))
print (class(summary$Year))
gvisColumnChart(summary,xvar = "Year",yvar = "TotalDeath",
options=list(chartArea="{right: 150}"))
})
plot_df <- reactive({
if (input$Sex1 == "All"){
return (data)
}else{
return (data %>% filter(Sex == input$Sex1))
}
})
Label<-reactive({
if(input$Sex1 == "All"){
return ("All")
}else if (input$Sex1 == "M"){
return ("Male")
}else{
return ("Female")
}
})
#Do the density plot for the death by sex with the facet wrap by race ethnicity
output$DeathByRaceAndSexDensity<-renderPlot({
ggplot(plot_df(),aes(x=Deaths)) + geom_density(aes(fill = Race_Ethnicity)) +
facet_wrap( ~ Race_Ethnicity) + xlab("Deaths") +
ggtitle(paste("Density Plot for",Label(),sep =' ')) +
theme(plot.title = element_text(hjust = 0.5)) +
guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(plot.title = element_text(size = 15, face = "bold"))
})
#Barchart for total death by race ethnicity for all years
output$TotalDeathByRaceEthnicityBarchart<-renderPlot({
group_by(data,Race_Ethnicity) %>%
summarise(.,Total_Death = sum(Deaths)) %>%
ggplot(., aes(reorder(Race_Ethnicity,-Total_Death),Total_Death,fill = Race_Ethnicity)) +
geom_bar(stat="identity") + guides(fill=guide_legend(title="Race Ethnicity")) +
xlab("Race Ethnicity") + ylab("Total Death") + ggtitle("Total Death by Race Ethnicity") +
theme(plot.title = element_text(hjust = 0.5)) + theme(plot.title = element_text(size = 15, face = "bold"))
})
#Plot the barchart for the top 5 leading causes
output$Top5LeadingCauses<-renderPlot({
groupByLeadingCause<-group_by(data,Leading.Cause)
summary<-summarise(groupByLeadingCause,sum = sum(Deaths,na.rm = T))
ggplot(arrange(summary,desc(sum))[1:5,],aes(reorder(Leading.Cause,-sum),sum,fill=Leading.Cause)) +
geom_bar(stat="identity") + guides(fill=guide_legend(title="Leading Cause")) +
scale_fill_discrete(breaks=c("Diseases of Heart (I00-I09, I11, I13, I20-I51)","Malignant Neoplasms (Cancer: C00-C97)","All Other Causes","Influenza (Flu) and Pneumonia (J09-J18)","Diabetes Mellitus (E10-E14)"))+
xlab("Leading Cause") + ylab("Total Death") +
scale_x_discrete(labels=c("Diseases of Heart","Malignant Neoplasms","All Other Causes","Influenza (Flu) and Pneumonia","Diabetes Mellitus")) +
ggtitle("Top 5 Leading Causes of Death") + theme(plot.title = element_text(hjust = 0.5)) + theme(plot.title = element_text(size = 15, face = "bold"))
})
#Plot barcharts for Heart Disease and Stroke Indicators (2012 -2014)
output$HeartDiseaseStrokeMortality<-renderPlot(
ggplot(HD1,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15)) + xlab('Race Ethnicity') + ylab('Mortality per 100,000 Population') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
output$HeartDiseaseStrokeHospitalizations<-renderPlot(
ggplot(HD2,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15))+ xlab('Race Ethnicity') + ylab('Hospitalizations per 10,000 population') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
#Plot barcharts for Injury-Related Indicators (2012-2014)
output$InjuryMortality<-renderPlot(
ggplot(IR1,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15)) + xlab('Race Ethnicity') + ylab('Mortality per 100,000 Population') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
output$InjuryHospitalizations<-renderPlot(
ggplot(IR2,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15)) + xlab('Race Ethnicity') + ylab('Hospitalizations per 100,000 Population')
+ theme(plot.title = element_text(size = 15, face = "bold"))
)
#Plot barcharts for Respiratory Disease Indicators (2012-2014)
output$RespiratoryMortality<-renderPlot(
ggplot(RD1,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15)) + xlab('Race Ethnicity') + ylab('Mortality per 100,000 Population') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
output$RespiratoryHospitalizations<-renderPlot(
ggplot(RD2,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=12)) + xlab('Race Ethnicity') + ylab('Hospitalizations per 100,000 Population') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
##Plot barcharts for Substance Abuse and Mental Health-Related Indicators
output$DrugSuicideMortality<-renderPlot(
ggplot(SAM1,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15)) + xlab('Race Ethnicity') + ylab('Mortality per 100,000 Population') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
output$DrugRelatedHospitalizations<-renderPlot(
ggplot(SAM2,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15)) + xlab('Race Ethnicity') + ylab('Hospitalizations per 100,000 Population') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
#Plot barcharts for Diabetes
output$DiabetesMortality<-renderPlot(
ggplot(DI1,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15)) + xlab('Race Ethnicity') + ylab('Mortality per 100,000 Population') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
output$DiabetesHospitalizations<-renderPlot(
ggplot(DI2,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15)) + xlab('Race Ethnicity') + ylab('Hospitalizations per 100,000 Population') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
#Plot barcharts for Cancer Indicators
output$CancerIncidence<-renderPlot(
ggplot(CI1,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15)) + xlab('Race Ethnicity') + ylab('Incidence per 100,000 Population') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
output$CancerMortality<-renderPlot(
ggplot(CI2,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15)) + xlab('Race Ethnicity') + ylab('Mortality per 100,000 Population') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
#Plot barcharts for Birth-Related indicators
output$InfantMortality<-renderPlot(
ggplot(BI,aes(x=factor(Race_Ethnicity),y=Mortality)) + facet_wrap(~MortalityType) +
geom_bar(stat="identity",aes(fill = factor(Race_Ethnicity))) + guides(fill=guide_legend(title = "Race Ethnicity")) +
theme(strip.text = element_text(size=15)) + xlab('Race Ethnicity') + ylab('Mortality per 1,000 live births') +
theme(plot.title = element_text(size = 15, face = "bold"))
)
#barchart for Death by year and leading cause
output$BarChart <- renderPlot({
m<-filter(data,Year == input$Year & Leading.Cause == input$LeadingCauseType)
p<-ggplot(m,aes(x=factor(Race_Ethnicity),y=Deaths))
p+geom_bar(stat="identity",aes(fill=Sex),position="dodge")+ xlab("Race Ethnicity") +
ggtitle(paste("Death by Race Ethnicity for The Year of",input$Year, sep = ' ')) +
theme(plot.title = element_text(hjust = 0.5)) + theme(plot.title = element_text(size = 15, face = "bold"))
})
#barchart for Total Death by year and leading cause
data1<-reactive({
data %>% filter(Year == input$Year1 & Leading.Cause == input$LeadingCauseType1)
})
output$BarChart1<- renderPlot({
#m<-filter(data,Year == input$Year1 & Leading.Cause == input$LeadingCauseType1)
p<-ggplot(data1(),aes(x=factor(Race_Ethnicity),y=Deaths))
p+geom_bar(stat="identity",aes(fill=Race_Ethnicity))+ xlab("Race Ethnicity") +
ggtitle(paste("Total Death by Race Ethnicity for The Year of",input$Year1, sep = ' ')) +
theme(plot.title = element_text(hjust = 0.5)) + guides(fill=guide_legend(title = "Race Ethnicity")) +
ylab("Total Death") + theme(plot.title = element_text(size = 15, face = "bold"))
})
#barchart for Total Death by leading cause
output$BarChart2 <- renderPlot({
m<-filter(data,Leading.Cause == input$LeadingCauseType2)
p<-ggplot(m,aes(x=factor(Race_Ethnicity),y=Deaths))
p+geom_bar(stat="identity",aes(fill=Race_Ethnicity))+ xlab("Race Ethnicity") +
ggtitle(paste("Total Death by Race Ethnicity for", input$LeadingCauseType2,sep=' ')) +
theme(plot.title = element_text(hjust = 0.5)) + theme(plot.title = element_text(size = 15, face = "bold"))
})
})
library(shiny)
library(shinydashboard)
library(dplyr)
library(dygraphs)
library(ggvis)
shinyUI(dashboardPage(
dashboardHeader(title = "NYC Leading Cause of Death",titleWidth = 290),
dashboardSidebar(width = 360,
sidebarMenu(
menuItem('Introduction',tabName = "Introduction",icon = icon("gear")),
menuItem('Trend',tabName = 'Trend',icon = icon("line-chart"),
menuSubItem("Death Trend Overview", tabName = "Trendline", icon = icon("line-chart")),
menuSubItem("Death Trend By Sex", tabName = "DeathTrendBySex", icon = icon("line-chart")),
menuSubItem("Death By Leading Cause Barchart", tabName = "LeadingCauseBarChart", icon = icon("bar-chart")),
menuSubItem("Trend By Leading Cause", tabName = "TrendByLeadingCause", icon = icon("line-chart")),
menuSubItem("Trend By Leading Cause and Race Ethnicity", tabName = "TrendByLeadingCauseAndRace",icon = icon("line-chart")),
menuSubItem("Death Trend by Race Ethnicity", tabName = "TrendLineByRaceEthnicity", icon = icon("line-chart")),
menuSubItem("Death By Sex", tabName = "DeathBySex", icon = icon("bar-chart-o"))),
menuItem("Death Distribution", tabName = "DeathByRaceAndSexDensity",icon = icon("area-chart")),
menuItem("Death Ranking", tabName = "Death Ranking",icon = icon("bar-chart"),
menuSubItem("Total Death By Race Ethnicity Ranking", tabName = "TotalDeathByRaceEthnicityBarchart", icon = icon("bar-chart")),
menuSubItem("Top 5 Leading Causes", tabName = "Top5LeadingCauses", icon = icon("bar-chart"))),
menuItem('Health Indicators',tabName = 'HealthIndicators',icon = icon("bar-chart"),
menuSubItem("Heart Disease and Stroke Indicators",tabName = "HeartDiseaseandStrokeIndicators",icon = icon("bar-chart")),
menuSubItem("Injury Related Indicators",tabName = "InjuryRelatedIndicators",icon = icon("bar-chart")),
menuSubItem("Respiratory Disease Indicators",tabName = "RespiratoryMortalityIndicators",icon = icon("bar-chart")),
menuSubItem("Substance Abuse/Mental Health-Related Indicators",tabName = "SubstanceAbuseMentalHealthIndicators",icon = icon("bar-chart")),
menuSubItem("Diabetes Indicators",tabName = "DiabetesIndicators",icon = icon("bar-chart")),
menuSubItem("Cancer Indicators",tabName = "CancerIndicators",icon = icon("bar-chart")),
menuSubItem("Birth Related Indicators",tabName = "BirthRelatedIndicators",icon = icon("bar-chart"))),
menuItem('Death By Race Ethnicity Comparison',tabName = 'DeathByRaceEthnicityComparison',icon = icon("bar-chart"),
menuSubItem("Death By Race Ethnicity and Leading Cause", tabName = "BarChart2", icon = icon("bar-chart")),
menuSubItem("Death By Race Ethnicity and Year/Leading Cause", tabName = "BarChart", icon = icon("bar-chart")),
menuSubItem("Total Death By Race Ethnicity and Year/Leading Cause", tabName = "BarChart1", icon = icon("bar-chart"))),
menuItem('Conclusion',tabName = "Conclusion",icon = icon("comments-o"))
)),
dashboardBody(
tabItems(
tabItem(tabName = 'Introduction',
fluidRow(h1('Introduction'),
img(src = "c.png",height = 400, width = 450)),
br(),
fluidRow(column(12,p("The death has changed dramatically and different types of leading causes have a significant impact on difference races (Asian and Pacific Island, Black Non-Hispanic, White Non-Hispanic, and Hispanic). We would like to analyze the leading causes of death and health indicators. The following questions could be answered: Which race has more deaths? Do females have more deaths than males? Which leading cause has a significant impact on the trend? What is the distribution for the deaths by year, race, and sex?")))),
tabItem(tabName = "Trendline",
fluidRow(column(12,dygraphOutput("Trendline")))),
tabItem(tabName = "DeathTrendBySex",
fluidRow(column(12,plotOutput("TrendlineBySex")))),
tabItem(tabName = "TrendLineByRaceEthnicity",
fluidRow(column(8,plotOutput("TrendLineByRaceEthnicity")),
column(4,checkboxGroupInput("Race_Ethnicity",label = h3("Select the race ethnicity"),
choices = c("Asian and Pacific Islander" = "Asian and Pacific Islander","Black Non-Hispanic" = "Black Non-Hispanic",
"White Non-Hispanic" = "White Non-Hispanic","Hispanic" = "Hispanic"),selected = "Hispanic",width = 600)))),
tabItem(tabName = "DeathBySex",
fluidRow(htmlOutput("DeathBySex"),height=800,width = "100%",
selectInput(inputId = "Sex",label = "Choose sex",choices = c("Male" = "M","Female" = "F")))),
tabItem(tabName = "DeathByRaceAndSexDensity",
fluidRow(column(12,plotOutput("DeathByRaceAndSexDensity"),selectInput(inputId = "Sex1",label = "Choose sex",choices = c("All"="All","Male" = "M",
"Female" = "F"))))),
tabItem(tabName = "TotalDeathByRaceEthnicityBarchart",
fluidRow(column(12,plotOutput("TotalDeathByRaceEthnicityBarchart")))),
tabItem(tabName = "Top5LeadingCauses",
fluidRow(column(12,plotOutput("Top5LeadingCauses")))),
tabItem(tabName = "HeartDiseaseandStrokeIndicators",
h3("Heart Disease and Stroke Mortality"),
fluidRow(column(12,plotOutput("HeartDiseaseStrokeMortality"))),
br(),
h3("Heart Disease and Stroke Hospitalizations"),
fluidRow(column(12,plotOutput("HeartDiseaseStrokeHospitalizations")))),
tabItem(tabName = "InjuryRelatedIndicators",
h3("Injury Related Mortality"),
fluidRow(column(12,plotOutput("InjuryMortality"))),
br(),
h3("Injury Related Hospitalizations"),
fluidRow(column(12,plotOutput("InjuryHospitalizations")))),
tabItem(tabName = "RespiratoryMortalityIndicators",
h3("Respiratory Mortality"),
fluidRow(column(12,plotOutput("RespiratoryMortality"))),
br(),
h3("Respiratory Hospitalizations"),
fluidRow(column(12,plotOutput("RespiratoryHospitalizations")))),
tabItem(tabName = "SubstanceAbuseMentalHealthIndicators",
h3("Substance Abuse Mental Health Mortality"),
fluidRow(column(12,plotOutput("DrugSuicideMortality"))),
br(),
h3("Substance Abuse Mental Health Hospitalizations"),
fluidRow(column(12,plotOutput("DrugRelatedHospitalizations")))),
tabItem(tabName = "DiabetesIndicators",
h3("Diabetes Mortality"),
fluidRow(column(12,plotOutput("DiabetesMortality"))),
br(),
h3("Diabetes Hospitalizations"),
fluidRow(column(12,plotOutput("DiabetesHospitalizations")))),
tabItem(tabName = "CancerIndicators",
h3("Cancer Incidence"),
fluidRow(column(12,plotOutput("CancerIncidence"))),
br(),
h3("Cancer Mortality"),
fluidRow(column(12,plotOutput("CancerMortality")))),
tabItem(tabName = "BirthRelatedIndicators",
h3("Birth Related Mortality"),
fluidRow(column(12,plotOutput("InfantMortality")))),
tabItem(tabName = "Conclusion",
fluidRow(column(12,h1(strong("Conclusion",align = "center",style = "font-family: 'times'; font-si19pt")),
p("Looking at the trend from 2007 to 2014, we see in the year of 2008 has the highest death number. What happened in the year of 2008? There is only a slight difference for the total death between 2007 and 2008. Where is the slight increasing coming from? Actually, the majority of deaths are from male. The major leading causes for the death increasing are Alzheimer's Disease, Chronic Liver Disease and Cirrhosis, Chronic Lower Respiratory Diseases, and Essential Hypertension and Renal Diseases. The year of 2012 has the least deaths over the period. The decreasing deaths are coming from the male. The major leading causes for the death drop down is Assault (Homicide), Cerebrovascular Disease (Stroke), Chronic Lower Respiratory Diseases, Human Immunodeficiency Virus Disease (HIV), Influenza (Flu) and Pneumonia, and Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use."),
br(),
p("The deaths for Asian and Pacific Islander are gradually increasing while Non-Hispanic has a downward trend. Hispanic deaths are increasing dramatically except there is a drop in 2009. Both male and female deaths dropped about half of deaths comparing with the deaths in 2008. Black Non-Hispanic deaths decreased dramatically till 2010 and had wiggling sign afterward. Comparing the trend between race ethnicity, Asian and Pacific Islander has the least deaths and White Non-Hispanic has the highest deaths. What are the leading causes make the deaths of White Non-Hispanic/Black Non-Hispanic so high? Heart Diseases is the number one leading cause but there might be different types of heart diseases. Also, all other causes are ranking number three. What are all other causes? Perhaps, health indicators might tell the story behind it. Coronary Heart Disease has high mortality for Black Non-Hispanic and White Non-Hispanic. Black mortality are slightly higher than white for the heart disease/stroke. White has a high risk on unintentional injury and elderlies have higher risk to fall. Black has high risk of Asthma/Chronic Lower Respiratory Hospitalizations. White has high suicide mortality and black has high drug related hospitalizations. Black has higher risk in diabetes. Both black and white are at high risk in cancer. Black has higher birth related mortality."),
br(),
p("Through the data exploratory data analysis, we conclude that the death trend of females has a significant impact on the overall trend. The health of females got significant improvement in 2009. Females have more deaths than males and breast cancer is one of the major leading causes of death for females. Black and White have higher health issues/hospitalizations than other races.")
))),
tabItem(tabName = "BarChart",
fluidRow(column(8,plotOutput("BarChart")),
column(4,sliderInput("Year",label = h3("Choose the year"),min = 2007, max = 2014, value = 2007,sep=''),
checkboxGroupInput("LeadingCauseType",label = h3("Select Leading Cause"),
choices = list("Accidents Except Drug Posioning"= "Accidents Except Drug Posioning (V01-X39, X43, X45-X59, Y85-Y86)",
"All Other Causes" = "All Other Causes",
"Alzheimer's Disease" = "Alzheimer's Disease (G30)",
"Assault (Homicide)" = "Assault (Homicide: Y87.1, X85-Y09)",
"Cerebrovascular Disease (Stroke)"= "Cerebrovascular Disease (Stroke: I60-I69)",
"Certain Conditions originating in the Perinatal Period" = "Certain Conditions originating in the Perinatal Period (P00-P96)",
"Chronic Liver Disease and Cirrhosis" = "Chronic Liver Disease and Cirrhosis (K70, K73)",
"Chronic Lower Respiratory Diseases" = "Chronic Lower Respiratory Diseases (J40-J47)",
"Congenital Malformations, Deformations, and Chromosomal Abnormalities" = "Congenital Malformations, Deformations, and Chromosomal Abnormalities (Q00-Q99)",
"Diabetes Mellitus"="Diabetes Mellitus (E10-E14)",
"Diseases of Heart" = "Diseases of Heart (I00-I09, I11, I13, I20-I51)",
"Essential Hypertension and Renal Diseases" = "Essential Hypertension and Renal Diseases (I10, I12)",
"Human Immunodeficiency Virus Disease (HIV)" = "Human Immunodeficiency Virus Disease (HIV: B20-B24)",
"Influenza (Flu) and Pneumonia"= "Influenza (Flu) and Pneumonia (J09-J18)",
"Intentional Self-Harm (Suicide)" = "Intentional Self-Harm (Suicide: X60-X84, Y87.0)",
"Malignant Neoplasms (Cancer)"= "Malignant Neoplasms (Cancer: C00-C97)",
"Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use"="Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use (F11-F16, F18-F19, X40-X42, X44)",
"Nephritis, Nephrotic Syndrome and Nephrisis" = "Nephritis, Nephrotic Syndrome and Nephrisis (N00-N07, N17-N19, N25-N27)",
"Septicemia"="Septicemia (A40-A41)"
),selected = "All Other Causes"))
)),
tabItem(tabName = "BarChart1",
fluidRow(column(8,plotOutput("BarChart1")),
column(4,sliderInput("Year1",label = h3("Choose the year"),min = 2007, max = 2014, value = 2007,sep=''),
checkboxGroupInput("LeadingCauseType1",label = h3("Select Leading Cause"),
choices = list("Accidents Except Drug Posioning"= "Accidents Except Drug Posioning (V01-X39, X43, X45-X59, Y85-Y86)",
"All Other Causes" = "All Other Causes",
"Alzheimer's Disease" = "Alzheimer's Disease (G30)",
"Assault (Homicide)" = "Assault (Homicide: Y87.1, X85-Y09)",
"Cerebrovascular Disease (Stroke)"= "Cerebrovascular Disease (Stroke: I60-I69)",
"Certain Conditions originating in the Perinatal Period" = "Certain Conditions originating in the Perinatal Period (P00-P96)",
"Chronic Liver Disease and Cirrhosis" = "Chronic Liver Disease and Cirrhosis (K70, K73)",
"Chronic Lower Respiratory Diseases" = "Chronic Lower Respiratory Diseases (J40-J47)",
"Congenital Malformations, Deformations, and Chromosomal Abnormalities" = "Congenital Malformations, Deformations, and Chromosomal Abnormalities (Q00-Q99)",
"Diabetes Mellitus"="Diabetes Mellitus (E10-E14)",
"Diseases of Heart" = "Diseases of Heart (I00-I09, I11, I13, I20-I51)",
"Essential Hypertension and Renal Diseases" = "Essential Hypertension and Renal Diseases (I10, I12)",
"Human Immunodeficiency Virus Disease (HIV)" = "Human Immunodeficiency Virus Disease (HIV: B20-B24)",
"Influenza (Flu) and Pneumonia"= "Influenza (Flu) and Pneumonia (J09-J18)",
"Intentional Self-Harm (Suicide)" = "Intentional Self-Harm (Suicide: X60-X84, Y87.0)",
"Malignant Neoplasms (Cancer)"= "Malignant Neoplasms (Cancer: C00-C97)",
"Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use"="Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use (F11-F16, F18-F19, X40-X42, X44)",
"Nephritis, Nephrotic Syndrome and Nephrisis" = "Nephritis, Nephrotic Syndrome and Nephrisis (N00-N07, N17-N19, N25-N27)",
"Septicemia"="Septicemia (A40-A41)"
),selected = "All Other Causes"))
)),
tabItem(tabName = "TrendByLeadingCause",
fluidRow(column(8,plotOutput("TrendByLeadingCause")),
column(4,checkboxGroupInput("Leading.Cause",label = h3("Select Leading Cause"),
choices = list("Accidents Except Drug Posioning"= "Accidents Except Drug Posioning (V01-X39, X43, X45-X59, Y85-Y86)",
"All Other Causes" = "All Other Causes",
"Alzheimer's Disease" = "Alzheimer's Disease (G30)",
"Assault (Homicide)" = "Assault (Homicide: Y87.1, X85-Y09)",
"Cerebrovascular Disease (Stroke)"= "Cerebrovascular Disease (Stroke: I60-I69)",
"Certain Conditions originating in the Perinatal Period" = "Certain Conditions originating in the Perinatal Period (P00-P96)",
"Chronic Liver Disease and Cirrhosis" = "Chronic Liver Disease and Cirrhosis (K70, K73)",
"Chronic Lower Respiratory Diseases" = "Chronic Lower Respiratory Diseases (J40-J47)",
"Congenital Malformations, Deformations, and Chromosomal Abnormalities" = "Congenital Malformations, Deformations, and Chromosomal Abnormalities (Q00-Q99)",
"Diabetes Mellitus"="Diabetes Mellitus (E10-E14)",
"Diseases of Heart" = "Diseases of Heart (I00-I09, I11, I13, I20-I51)",
"Essential Hypertension and Renal Diseases" = "Essential Hypertension and Renal Diseases (I10, I12)",
"Human Immunodeficiency Virus Disease (HIV)" = "Human Immunodeficiency Virus Disease (HIV: B20-B24)",
"Influenza (Flu) and Pneumonia"= "Influenza (Flu) and Pneumonia (J09-J18)",
"Intentional Self-Harm (Suicide)" = "Intentional Self-Harm (Suicide: X60-X84, Y87.0)",
"Malignant Neoplasms (Cancer)"= "Malignant Neoplasms (Cancer: C00-C97)",
"Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use"="Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use (F11-F16, F18-F19, X40-X42, X44)",
"Nephritis, Nephrotic Syndrome and Nephrisis" = "Nephritis, Nephrotic Syndrome and Nephrisis (N00-N07, N17-N19, N25-N27)",
"Septicemia"="Septicemia (A40-A41)"
),selected = "All Other Causes")))),
tabItem(tabName = "TrendByLeadingCauseAndRace",
fluidRow(column(8,plotOutput("TrendByLeadingCauseAndRace")),
column(4,checkboxGroupInput("RaceSelection",label = h3("Select Race Ethnicity"), choices = list("Asian and Pacific Islander"="Asian and Pacific Islander","Black Non-Hispanic" = "Black Non-Hispanic","Hispanic" = "Hispanic", "White Non-Hispanic" = "White Non-Hispanic")),
checkboxGroupInput("LeadingCauseType10",label = h3("Select Leading Cause"),
choices = list("Accidents Except Drug Posioning"= "Accidents Except Drug Posioning (V01-X39, X43, X45-X59, Y85-Y86)",
"All Other Causes" = "All Other Causes",
"Alzheimer's Disease" = "Alzheimer's Disease (G30)",
"Assault (Homicide)" = "Assault (Homicide: Y87.1, X85-Y09)",
"Cerebrovascular Disease (Stroke)"= "Cerebrovascular Disease (Stroke: I60-I69)",
"Certain Conditions originating in the Perinatal Period" = "Certain Conditions originating in the Perinatal Period (P00-P96)",
"Chronic Liver Disease and Cirrhosis" = "Chronic Liver Disease and Cirrhosis (K70, K73)",
"Chronic Lower Respiratory Diseases" = "Chronic Lower Respiratory Diseases (J40-J47)",
"Congenital Malformations, Deformations, and Chromosomal Abnormalities" = "Congenital Malformations, Deformations, and Chromosomal Abnormalities (Q00-Q99)",
"Diabetes Mellitus"="Diabetes Mellitus (E10-E14)",
"Diseases of Heart" = "Diseases of Heart (I00-I09, I11, I13, I20-I51)",
"Essential Hypertension and Renal Diseases" = "Essential Hypertension and Renal Diseases (I10, I12)",
"Human Immunodeficiency Virus Disease (HIV)" = "Human Immunodeficiency Virus Disease (HIV: B20-B24)",
"Influenza (Flu) and Pneumonia"= "Influenza (Flu) and Pneumonia (J09-J18)",
"Intentional Self-Harm (Suicide)" = "Intentional Self-Harm (Suicide: X60-X84, Y87.0)",
"Malignant Neoplasms (Cancer)"= "Malignant Neoplasms (Cancer: C00-C97)",
"Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use"="Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use (F11-F16, F18-F19, X40-X42, X44)",
"Nephritis, Nephrotic Syndrome and Nephrisis" = "Nephritis, Nephrotic Syndrome and Nephrisis (N00-N07, N17-N19, N25-N27)",
"Septicemia"="Septicemia (A40-A41)"
),selected = "All Other Causes"))
)),
tabItem(tabName = "LeadingCauseBarChart",
fluidRow(column(8,plotOutput("DeathBySexLeadingCause")),
column(4,selectInput(inputId = "Sex5",label = "Choose sex",choices = c("All" = "All","Male" = "M","Female" = "F")),checkboxGroupInput("Leading.Cause1",label = h3("Select Leading Cause"),
choices = list("Accidents Except Drug Posioning"= "Accidents Except Drug Posioning (V01-X39, X43, X45-X59, Y85-Y86)",
"All Other Causes" = "All Other Causes",
"Alzheimer's Disease" = "Alzheimer's Disease (G30)",
"Assault (Homicide)" = "Assault (Homicide: Y87.1, X85-Y09)",
"Cerebrovascular Disease (Stroke)"= "Cerebrovascular Disease (Stroke: I60-I69)",
"Certain Conditions originating in the Perinatal Period" = "Certain Conditions originating in the Perinatal Period (P00-P96)",
"Chronic Liver Disease and Cirrhosis" = "Chronic Liver Disease and Cirrhosis (K70, K73)",
"Chronic Lower Respiratory Diseases" = "Chronic Lower Respiratory Diseases (J40-J47)",
"Congenital Malformations, Deformations, and Chromosomal Abnormalities" = "Congenital Malformations, Deformations, and Chromosomal Abnormalities (Q00-Q99)",
"Diabetes Mellitus"="Diabetes Mellitus (E10-E14)",
"Diseases of Heart" = "Diseases of Heart (I00-I09, I11, I13, I20-I51)",
"Essential Hypertension and Renal Diseases" = "Essential Hypertension and Renal Diseases (I10, I12)",
"Human Immunodeficiency Virus Disease (HIV)" = "Human Immunodeficiency Virus Disease (HIV: B20-B24)",
"Influenza (Flu) and Pneumonia"= "Influenza (Flu) and Pneumonia (J09-J18)",
"Intentional Self-Harm (Suicide)" = "Intentional Self-Harm (Suicide: X60-X84, Y87.0)",
"Malignant Neoplasms (Cancer)"= "Malignant Neoplasms (Cancer: C00-C97)",
"Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use"="Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use (F11-F16, F18-F19, X40-X42, X44)",
"Nephritis, Nephrotic Syndrome and Nephrisis" = "Nephritis, Nephrotic Syndrome and Nephrisis (N00-N07, N17-N19, N25-N27)",
"Septicemia"="Septicemia (A40-A41)"
),selected = "All Other Causes"))
)),
tabItem(tabName = "BarChart2",
fluidRow(column(8,plotOutput("BarChart2")),
column(4,checkboxGroupInput("LeadingCauseType2",label = h3("Select Leading Cause"),
choices = list("Accidents Except Drug Posioning"= "Accidents Except Drug Posioning (V01-X39, X43, X45-X59, Y85-Y86)",
"All Other Causes" = "All Other Causes",
"Alzheimer's Disease" = "Alzheimer's Disease (G30)",
"Assault (Homicide)" = "Assault (Homicide: Y87.1, X85-Y09)",
"Cerebrovascular Disease (Stroke)"= "Cerebrovascular Disease (Stroke: I60-I69)",
"Certain Conditions originating in the Perinatal Period" = "Certain Conditions originating in the Perinatal Period (P00-P96)",
"Chronic Liver Disease and Cirrhosis" = "Chronic Liver Disease and Cirrhosis (K70, K73)",
"Chronic Lower Respiratory Diseases" = "Chronic Lower Respiratory Diseases (J40-J47)",
"Congenital Malformations, Deformations, and Chromosomal Abnormalities" = "Congenital Malformations, Deformations, and Chromosomal Abnormalities (Q00-Q99)",
"Diabetes Mellitus"="Diabetes Mellitus (E10-E14)",
"Diseases of Heart" = "Diseases of Heart (I00-I09, I11, I13, I20-I51)",
"Essential Hypertension and Renal Diseases" = "Essential Hypertension and Renal Diseases (I10, I12)",
"Human Immunodeficiency Virus Disease (HIV)" = "Human Immunodeficiency Virus Disease (HIV: B20-B24)",
"Influenza (Flu) and Pneumonia"= "Influenza (Flu) and Pneumonia (J09-J18)",
"Intentional Self-Harm (Suicide)" = "Intentional Self-Harm (Suicide: X60-X84, Y87.0)",
"Malignant Neoplasms (Cancer)"= "Malignant Neoplasms (Cancer: C00-C97)",
"Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use"="Mental and Behavioral Disorders due to Accidental Poisoning and Other Psychoactive Substance Use (F11-F16, F18-F19, X40-X42, X44)",
"Nephritis, Nephrotic Syndrome and Nephrisis" = "Nephritis, Nephrotic Syndrome and Nephrisis (N00-N07, N17-N19, N25-N27)",
"Septicemia"="Septicemia (A40-A41)"
),selected = "All Other Causes"))
)
)))))
@tommyhuang1
Copy link
Author

Shiny App codes are added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment