-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
89 lines (78 loc) · 2.74 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Rexford Cristal
# Healthcare Analytics, Fall 2018
# Final Project
#
# 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(readr)
library(data.table)
library(tables)
library(plyr)
library(dplyr)
library(sqldf)
library(ggplot2)
library(plotrix)
healthdata_dx = read.csv("data/healthdata_dx.csv")
labels <- sqldf("select distinct pt_disposition from healthdata_dx")
labels$pt_disposition <- as.character(labels$pt_disposition)
labels2 <- c(head(labels$pt_disposition, 5))
pt_disposition_count <- c(head(healthdata_dx$N, 5))
piepercent <- round(100 * pt_disposition_count / sum(pt_disposition_count), 1)
healthdata2_expired = read.csv("data/healthdata2_expired.csv")
healthdata2_expired$LOS2 <- parse_number(healthdata2_expired$LOS)
ui <- fluidPage(
titlePanel("NYU Healthcare Analytics Project",
windowTitle = "New York University Healthcare Analytics Project"),
mainPanel(
"Rexford Cristal, MD",
hr(),
h3("Sudden Cardiac Arrest, Ventricular Fibrillation, and Patient Disposition", align = "center"),
plotOutput("pie"),
fluidRow(
column(4,
selectInput("pd",
"Patient Disposition:",
c("All",
unique(as.character(healthdata_dx$pt_disposition))))
)
),
dataTableOutput("table"),
hr(),
h3("Length of Stay and Expiration", align = "center"),
plotOutput("q", hover = "plot_hover"),
verbatimTextOutput("info"),
hr(),
"Source: Hospital Inpatient Discharges (SPARCS De-Identified), 2016",
width = 12
)
)
server <- function(input, output) {
output$pie <- renderPlot({
pie(pt_disposition_count, labels = piepercent, main = "Percentage of Patients with SCA or VF By Patient Disposition in NY State (SPARCS 2016)", col = rainbow(length(labels2)))
legend("bottomleft", labels, cex = 1, fill = rainbow(length(pt_disposition_count)), legend = labels2)
})
output$table <- renderDataTable(data.table({
data <- healthdata_dx
if (input$pd != "All") {
data <- data[data$pt_disposition == input$pd,]
}
data
}))
output$q <- renderPlot({
qplot(LOS2, N, data = healthdata2_expired, main = "Relationship Between Length of Stay and Number of Expired Patients (N) in NY State (SPARCS 2016)", xlab = "Length of Stay", ylab = "Expired Patients (N)", color = N)
})
output$info <- renderText({
xy_str <- function(e) {
if(is.null(e)) return("NULL\n")
paste0("x=", round(e$x, 1), " y=", round(e$y, 1), "\n")
}
paste0("hover: ", xy_str(input$plot_hover))
})
}
shinyApp(ui = ui, server = server)