---
title: "OWID Country Indicators"
output: flexdashboard::flex_dashboard
runtime: shiny
---
```{r global, include=FALSE}
# load data in 'global' chunk so it can be shared
# by all users of the dashboard
library(dplyr)
library(datasets)
library(highcharter)
library(fpp3)
library(RColorBrewer)
library(openxlsx)
library(leaflet)
library(geojsonio)
library(plotly)
library(ggplot2)
library(tidyverse)
```
```{r,message=FALSE,echo=FALSE}
owid_country <- openxlsx::read.xlsx('https://ctim.es/AEDV/data/owid_country.xlsx',sheet=1) %>%
as_tibble()
geoj <- geojsonio::geojson_read('https://ctim.es/AEDV/data/geo_countries.geojson',what = "sp")
geoj_ti <- geoj %>% as_tibble()
join <- left_join(geoj_ti,owid_country,by = c("ISO_A3" = "iso_code"))
```
Column {.sidebar data-width=240}
--------------------------------------------------
```{r}
selectInput(
"indicator",
label = "Indicator:",
choices = colnames(owid_country)[-(1:3)],
selected = colnames(owid_country)[-(1:3)][1]
)
```
###
```{r}
renderTable({
data <- join[[which(names(join)==input$indicator)]]
tibble(
country=join$ADMIN,
value=round(data,digits=2)
) %>%
filter(is.na(value)==FALSE) %>%
arrange(desc(value)) %>%
mutate(value=prettyNum(round(value,digits=2))) %>%
head(300)
})
```
Column
--------------------------------------------------
###
```{r}
leaflet::renderLeaflet({
data <- join[[which(names(join)==input$indicator)]]
etiquetas <-paste(" ",join$ADMIN ,"
",input$indicator,": ",prettyNum(round(data,digits=2), big.mark = ",", scientific = FALSE)) %>%
lapply(htmltools::HTML)
pal <- leaflet::colorQuantile("YlOrRd", data, n = 9)
geoj %>%
leaflet::leaflet() %>%
leaflet::setView(lng = 25, lat = 22, zoom = 2) %>%
leaflet::addPolygons(
fillColor = ~pal(data),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlightOptions = leaflet::highlightOptions(
weight = 2,
color = rgb(0.2,0.2,0.2),
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE
),
label = etiquetas
) %>%
leaflet::addControl(input$indicator, position = "topright") %>%
leaflet::addLegend("topright", pal = pal, values = data,
title = " ", #input$indicator,
labFormat = function(type, cuts, p) {
n = length(cuts)
x = (cuts[-n] + cuts[-1])/2
x=prettyNum(round(x,digits=2), big.mark = ",", scientific = FALSE)
as.character(x)
},
opacity = 1
)
})
```