-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
160 lines (122 loc) · 5.96 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
library(dplyr)
library(spdplyr)
library(tidyr)
library(leaflet)
library(readxl)
library(scales)
library(echarts4r)
library(shiny)
library(bslib)
datoscovid <- read_excel("datacovid.xlsx")
coordenadas <- read_excel("world_countrys.xlsx")
datoscov1 <- datoscovid |>
left_join(coordenadas, by = c("location" = "name"))
theme <- bs_theme(
bg = "#000000", fg = "#B8BCC2",
"input-border-color" = "#a6a6a6"
)
ui <- bootstrapPage(
absolutePanel(
top = 10, left = 50, style = "z-index:500; text-align: right;",
tags$h2("El COVID en América")
),
theme = theme,
tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
leafletOutput("map", width = "100%", height = "100%"),
absolutePanel(top = 10, right = 10,
fluidRow(column(width = 5, dateInput("fecha", "Fecha a graficar (mapa):", width = 180,value = "2021-02-12") ),
selectInput("var", "Histórico del país:", width = 180,
c("Antigua y Barbuda" = "Antigua and Barbuda",
"Argentina" = "Argentina",
"Bahamas" = "Bahamas",
"Barbados" = "Barbados",
"Belice" = "Belize",
"Bolivia" = "Bolivia",
"Brasil" = "Brazil",
"Canada" = "Canada",
"Chile" = "Chile",
"Colombia" = "Colombia",
"Costa Rica" = "Costa Rica",
"Cuba" = "Cuba",
"Dominica" = "Dominica",
"Republica Dominicana" = "Dominican Republic",
"Ecuador" = "Ecuador",
"El Salvador" = "El Salvador",
"Groenlandia" = "Greenland",
"Grenada" = "Grenada",
"Guatemala" = "Guatemala",
"Guyana" = "Guyana",
"Haiti" = "Haiti",
"Honduras" = "Honduras",
"Jamaica" = "Jamaica",
"Mexico" = "Mexico",
"Nicaragua" = "Nicaragua",
"Panama" = "Panama",
"Paraguay" = "Paraguay",
"Peru" = "Peru",
"Trinidad y Tobago" = "Trinidad and Tobago",
"Estados Unidos" = "United States",
"Uruguay" = "Uruguay",
"Venezuela" = "Venezuela"
), selected = "Mexico" )),
echarts4rOutput("graf", height = '350px', width = '550px'),
echarts4rOutput("graf1", height = '350px', width = '550px')
)
)
server <- function(input, output){
datos <- reactive({
datoscov1 |>
filter(date == input$fecha)
})
output$map <- renderLeaflet({
mytext <- paste(
"Fecha: ", datos()$date, "<br/>",
"País: ", datos()$location, "<br/>",
"Casos totales: ", comma(datos()$total_cases), "<br/>",
"Muertes totales: ", comma(datos()$total_deaths), sep="") %>%
lapply(htmltools::HTML)
paleta <- colorBin( palette="Reds", domain=datos()$new_cases, na.color="transparent", bins=5)
leaflet() %>%
addTiles("http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",
attribution = paste(
"© <a href=\"http://openstreetmap.org\">OpenStreetMap</a> contributors",
"© <a href=\"http://cartodb.com/attributions\">CartoDB</a>"
)) %>%
setView( lat=23, lng=-50 , zoom=3) %>%
addCircleMarkers(~longitude, ~latitude,
data = datos(),
fillColor = ~paleta(new_cases), fillOpacity = 0.7, color="white", radius=~new_cases^(1/3), stroke=FALSE,
label = mytext,
labelOptions = labelOptions( style = list("font-weight" = "normal", padding = "3px 8px"), textsize = "13px", direction = "auto")
) %>%
addLegend( pal=paleta, values=~new_cases, opacity=0.9, title = "Magnitude", position = "bottomleft", data = datos() )
})
dato <- reactive({
datoscovid |>
filter(location == input$var)
})
output$graf <- renderEcharts4r({
dato() |>
e_charts(date) |>
e_line(new_cases, name = "casos nuevos", symbol = "none") |>
e_line(new_cases_smoothed, name = "Media movil", symbol = "none") |>
e_tooltip(trigger = "axis") |>
e_theme("inspired") |>
e_title("Evolución del COVID") |>
e_legend(right = 50) |>
e_color(color = c("#853c3c","#3c6885"))
})
output$graf1 <- renderEcharts4r({
datos() |>
arrange(new_cases ) |>
top_n(5, new_cases) |>
e_charts(location) |>
e_bar(new_cases, name = "Casos nuevos") |>
e_flip_coords() |>
e_tooltip(trigger = "axis") |>
e_color(color = "#853c3c") |>
e_theme("inspired") |>
e_title( "Top 5 países" )
})
}
shinyApp(ui, server)