Press play or pause to go through maps. There is a default waiting period of 20 seconds for each map, to allow for loading time.
file<-'https://raw.githubusercontent.com/MervynOLuing/TanzaniaShapefiles/master/TanzaniaRegionCodesGDPPct.csv'
region<-read.csv(url(file))
library("shiny")
library("flexdashboard")
library(sf)
library(ggplot2)
library(rgdal)
library(ggsn)
library(tmap)
library(leaflet)
names(region)<-c("Region_Nam","2007","2010","2011","2012","2013","2014","2015","2016")
# Download data.zip from the web
download.file("http://www.nbs.go.tz/nbs/takwimu/references/GIS_Maps.zip", "maps.zip")
# Unzip file
unzip("maps.zip")
TanzmyDFW <- st_read("Water_body.shp", quiet = TRUE, stringsAsFactors = FALSE)
TanzmyDF <- st_read("Regions.shp",quiet = TRUE, stringsAsFactors = FALSE)
TanzReg <- merge( TanzmyDF, region, by='Region_Nam')
df<-as.data.frame( region )
runApp(list(
ui = fluidPage(
titlePanel("Tmap time series"),
sidebarLayout(
sidebarPanel(
sliderInput("year", "Year",
min=min(c(2010,2011,2012,2013,2014,2015,2016)), max=max(c(2010,2011,2012,2013,2014,2015,2016)),
value = min(c(2010,2011,2012,2013,2014,2015,2016)), animate =
animationOptions(interval = 20000, loop = TRUE))
),
mainPanel(
leafletOutput("map")
)
)
),
server = function(input, output) {
output$map = renderLeaflet({
(Tanzania <- tm_shape(TanzReg[as.character(input$year)]) +
tm_polygons(col =as.character(input$year),
title=paste0("Regional GDP at Current \nMarket Prices - ",as.factor(input$year)), title.size = 1) +
tm_layout(main.title = paste0("Regional Shares of GDP at Current Market Prices, Tanzania Mainland",as.factor(input$year)) ,
main.title.position = c("top", "center") ,
main.title.size = 1))
(TanzaniaB <- tm_shape(TanzmyDFW) + tm_fill(col = "lightblue") )
(TanzaniaA <- Tanzania + TanzaniaB)
tmap_leaflet(TanzaniaA)
})
}
))