Proloy Barua1
R is always pointed at a directory on our computer. We can find out which directory by running the getwd (get working directory) function without arguments. To change our working directory, we use setwd (set working directory) function and specify the path to the desired folder. We need to set working directory and path after cleaning up everything including your global environment of both r objects and loaded packages. Sometimes it is useful to Check r-version using print(version$version.string) function to be compatible for analysis to some extent.
rm(list=ls()) # Clean up everything
# Set working directory
setwd("F:/Maps") # setting path of working directory
print(version$version.string) # Checking r-versionAs soon as local directory is set, we need to load required R packages such as tidyverse (Wickham, 2021), leaflet (Cheng, Karambelkar, et al., 2021), leafpop (Appelhans & Detsch, 2021), magrittr (Bache & Wickham, 2020), htmltools (Cheng, Sievert, et al., 2021), rjson (Couture-Beil, 2018), jsonlite (Ooms, 2020), reactable (Lin, 2020), htmlwidgets (Vaidyanathan et al., 2020), readr (Wickham & Hester, 2020), and glue (Hester, 2020).
# Loading packages
library("tidyverse")
library("leaflet")
library("htmltools")
library("leafpop")
library("magrittr")
library("rjson")
library("jsonlite")
library("reactable")
library("htmlwidgets")
library("dplyr")
library("glue")
library("sf")The next step is to load primary data, stored at local directory.
# Loading data from local directory mph_17th <- readr::read_csv("F:/Maps/mph_17th.csv")
## Creating popup labels
popup_labels <- glue::glue("<strong><span style='color:red'><span style='font-size: 25px'> Student Profile</strong></span><br/>
Student Name: <b><span style='color:blue'>{mph_17th$Name}<br/></span></b>
Country: <b><span style='color:orange'>{mph_17th$Country}<br/></span></b>
Last degree: <b><span style='color:green'>{mph_17th$Last_degree}<br/></span></b>
Category: <b><span style='color:deeppink'>{mph_17th$Category}<br/></span></b>
MPH Cohort: <b><span style='color:chartreuse'> {mph_17th$MPH_cohort} </span><br/></b>
Why are you here: <b><span style='color:blue'>{mph_17th$Why_here}<br/></span></b>
Why now: <b><span style='color:blue'>{mph_17th$Why_now}<br/></span><br/>") %>%
lapply(htmltools::HTML)
# use the default base map which is OpenStreetMap tiles
## Making a title of Map
tag.map.title <- tags$style(HTML("
.leaflet-control.map-title {
transform: translate(-50%,20%);
position: fixed !important;
left: 50%;
text-align: center;
padding-left: 10px;
padding-right: 10px;
background: rgba(255,255,255,0.75);
font-weight: bold;
font-size: 16px;
}
"))
title <- tags$h3(
tag.map.title, HTML("Master of Public Health (MPH) 17th Cohort, BRAC JPGSPH")
)
mph_17th <- leaflet::leaflet() %>%
leaflet::addTiles() %>%
#addProviderTiles(providers$Esri.WorldImagery, group = "World Imagery") %>%
#addProviderTiles(providers$Stamen.TonerLite, group = "Toner Lite") %>%
#addProviderTiles(providers$OpenStreetMap, group = "Open SM") %>%
addControl(title, position = "topleft", className="map-title") %>%
leaflet::addMarkers(lng=mph_17th$Longitude, lat=mph_17th$Latitude, clusterOptions = markerClusterOptions(),
popup = popup_labels, popupOptions = popupOptions(closeOnClick = FALSE, keepInView = TRUE, closeButton = TRUE)) %>%
# setView(lng = 132.016716, lat = 38.130070, zoom = 1) %>%
addMeasure(
position = 'bottomleft',
primaryLengthUnit = 'meters',
primaryAreaUnit = 'sqmeters',
activeColor = '#3D535D',
completedColor = '#7D4479') %>%
addControl("<b><span style='color:blue'><span style='font-size: 14px'>To measure distance between JPGSPH located in Bangladesh and other countries click bottom leaft corner button</br>",
position = 'bottomright')
# Saving map as html file
htmlwidgets::saveWidget(widget = mph_17th,
file = "mph_17th_cohort.html",
selfcontained = TRUE)mph_17thLocations of Master of Public Health (MPH) Students, 17th Cohort (2021), BRAC JPGSPH
BRAC James P Grant School of Public Health, BRAC University, Dhaka-1213, Bangladesh, Corresponding Author’s Email: proloy.barua@bracu.ac.bd
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License↩︎