-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProvince_property.R
134 lines (127 loc) · 4.02 KB
/
Province_property.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
library(shiny)
library(shinysky)
library(shinydashboardPlus)
ui_province_property <- function(id) {
ns <- NS(id)
tagList(
uiOutput(ns("pl"))
)
}
server_province_property <- function(input, output, session, data, var2show, showLABEL = TRUE, Log = FALSE) {
ns <- session$ns
output$pl <- renderUI(
if (nrow(data()) > 0) {
tagList(
tagList(
box(
title = "Descriptive Statistics", boxToolSize = "lg", width = 12, collapsible = TRUE, background = "light-blue",
# HTML("<center style = 'color:blue;font-size:20px;font-weight:bold'>Descriptive Statistics</center>"),
hotable(ns("tbl")),
plotlyOutput(ns("plt2"))
)
)
)
}
)
output$plt2 <- renderPlotly({
if (showLABEL) {
data() %>%
plot_ly(x = ~DateRep) %>%
add_lines(
y = formula(paste0("~", ifelse(str_starts(var2show, "cum"), "cum_cases", "Cases"))),
name = "Confirmed", marker = list(size = 6)
) %>%
add_lines(
y = formula(paste0("~", ifelse(str_starts(var2show, "cum"), "cum_death", "Deaths"))),
name = "Deaths", marker = list(size = 6)
) %>%
layout(
# paper_bgcolor = "gray",
yaxis = list(title = "", type = ifelse(Log, "log", "linear")),
# plot_bgcolor = "lightblue",
legend = ~ list(title = list(
text = paste0("Region: ", as.character(unique(Province))),
font = list(size = 20, color = "red")
)),
title = list(text = "Per 1M", font = list(size = 15, color = "black"), x = 0.01, y = .98)
)
} else {
data() %>%
plot_ly(x = ~DateRep) %>%
add_lines(
y = formula(paste0("~", ifelse(str_starts(var2show, "cum"), "cum_cases", "Cases"))),
name = "Confirmed", marker = list(size = 6)
) %>%
add_lines(
y = formula(paste0("~", ifelse(str_starts(var2show, "cum"), "cum_death", "Deaths"))),
name = "Deaths", marker = list(size = 6)
) %>%
add_lines(
y = formula(paste0("~", ifelse(str_starts(var2show, "cum"), "cum_recovered", "Recovered"))),
name = "Recovered", marker = list(size = 6)
) %>%
layout(
# paper_bgcolor = "lightblue",
yaxis = list(title = "", type = ifelse(Log, "log", "linear")),
xaxis = list(title = "Date reported"), # plot_bgcolor = "lightblue",
legend = ~ list(title = list(
text = paste0("Region: ", as.character(unique(Province))),
font = list(size = 20, color = "red")
))
)
}
})
output$tbl <- renderHotable({
f <- function(x) {
xday <- min(which(x != 0))
if (is.infinite(xday)) {
# x <- x[xday:length(x)]
c(
Total = NA, SQ = NA,
median = NA, mean = NA, SQ = NA,
max = NA, sd = NA,
day = NA, xday = NA
)
} else {
day <- which.max(x)
x <- x[xday:length(x)]
c(
Total = sum(x), SQ = quantile(x, 0.25),
median = median(x), mean = mean(x), SQ = quantile(x, .75),
max = max(x), sd = round(sd(x), 2),
day = day, xday = xday
)
}
}
if (showLABEL) {
df <- data() %>%
select(Cases, Deaths) %>%
sapply(f) %>%
t() %>%
as.data.frame()
} else {
df <- data() %>%
select(Cases, Deaths, Recovered) %>%
sapply(f) %>%
t() %>%
as.data.frame()
}
cbind(
Region = data()$Province[1:nrow(df)], Feature = rownames(df), df[-c(length(df), length(df) - 1)],
Date_of_1st_case = (data()$DateRep[df$xday]), Date_of_peak = data()$DateRep[df$day]
)
})
}
ui <- fluidPage(
ui_province_property("f_1")
)
server <- function(input, output) {
data <- data
data2 <- compute_cum_ranks(data)
data3 <- reactive({
data2 %>%
filter(Province %in% "an giang")
})
callModule(server_province_property, "f_1", data3, "cum_cases")
}
shinyApp(ui, server)