I have this app. It mostly works in that it colors countries according to their rank. However, I can’t get it to recognise all countries. Specifically: Republic of the Congo, Democratic Republic of the Congo, North Korea, South Korea, South Sudan, Taiwan, Equatorial Guinea, and Western Sahara. You can see that they appear in white even though I have rank data for them.
Here is the code for the app: `
library(shiny)
library(googleVis)
library(dplyr)
# Define UI
ui <- fluidPage(
titlePanel("Climate Vulnerability and Readiness"),
sidebarLayout(
sidebarPanel(
selectInput("year", "Select Year", choices = 1995:2021, selected = 2021),
selectInput("category", "Select Category",
choices = list("Capacity" = "vul_capacity", "Economic" = "vul_economic",
"Ecosystems" = "vul_ecosystems", "Exposure" = "vul_exposure",
"Food" = "vul_food", "Habitat" = "vul_habitat",
"Health" = "vul_health", "Infrastructure" = "vul_infrastructure",
"Sensitivity" = "vul_sensitivity", "Vulnerability" = "vul_vulnerability",
"Water" = "vul_water"), selected = "vul_capacity")
),
mainPanel(
htmlOutput("map")
)
)
)
# Define server logic
server <- function(input, output) {
output$map <- renderGvis({
year <- input$year
category <- input$category
# Create the column name for the selected year and category
rank_column <- paste(category, "_Rank_", year, sep = "")
# Filter and prepare the data
map_data <- combined_vul_data_stack %>%
select(ISO3, Name, Rank = !!sym(rank_column)) %>%
mutate(Tooltip = ifelse(is.na(Rank), paste(Name, "- Insufficient data"), paste(Name)))
# Determine the range of the Rank values
min_rank <- min(map_data$Rank, na.rm = TRUE)
max_rank <- max(map_data$Rank, na.rm = TRUE)
# Create the map
gvisGeoChart(map_data, locationvar = "Name", colorvar = "Rank",
hovervar = "Tooltip", # Use the Tooltip column
options = list(colorAxis = paste0("{minValue:", min_rank, ", maxValue:", max_rank, ", colors:['#00FF00', '#FFFF00', '#FF0000']}"),
backgroundColor = '#81d4fa', datalessRegionColor = '#f5f5f5',
defaultColor = '#f5f5f5',
tooltip = "{isHtml: true}"))
})
}
# Run the application
shinyApp(ui = ui, server = server)
`
I have simplified the dataset to only include the capacity category in year 2021. The app should run fine for these selections.
dput(combined_vul_data_stack)
structure(list(ISO3 = c("AFG", "ALB", "DZA", "AND", "AGO", "ATG",
"ARG", "ARM", "AUS", "AUT", "AZE", "BHS", "BHR", "BGD", "BRB",
"BLR", "BEL", "BLZ", "BEN", "BTN", "BOL", "BIH", "BWA", "BRA",
"BRN", "BGR", "BFA", "BDI", "KHM", "CMR", "CAN", "CPV", "CAF",
"TCD", "CHL", "CHN", "COL", "COM", "COG", "COD", "CRI", "CIV",
"HRV", "CUB", "CYP", "CZE", "DNK", "DJI", "DMA", "DOM", "ECU",
"EGY", "SLV", "GNQ", "ERI", "EST", "ETH", "FJI", "FIN", "FRA",
"GAB", "GMB", "GEO", "DEU", "GHA", "GRC", "GRD", "GTM", "GIN",
"GNB", "GUY", "HTI", "HND", "HUN", "ISL", "IND", "IDN", "IRN",
"IRQ", "IRL", "ISR", "ITA", "JAM", "JPN", "JOR", "KAZ", "KEN",
"KIR", "PRK", "KOR", "KWT", "KGZ", "LAO", "LVA", "LBN", "LSO",
"LBR", "LBY", "LIE", "LTU", "LUX", "MKD", "MDG", "MWI", "MYS",
"MDV", "MLI", "MLT", "MHL", "MRT", "MUS", "MEX", "FSM", "MDA",
"MCO", "MNG", "MNE", "MAR", "MOZ", "MMR", "NAM", "NRU", "NPL",
"NLD", "NZL", "NIC", "NER", "NGA", "NOR", "OMN", "PAK", "PLW",
"PAN", "PNG", "PRY", "PER", "PHL", "POL", "PRT", "QAT", "ROU",
"RUS", "RWA", "KNA", "LCA", "VCT", "WSM", "SMR", "STP", "SAU",
"SEN", "SRB", "SYC", "SLE", "SGP", "SVK", "SVN", "SLB", "SOM",
"ZAF", "ESP", "LKA", "SDN", "SUR", "SWZ", "SWE", "CHE", "SYR",
"TJK", "TZA", "THA", "TLS", "TGO", "TON", "TTO", "TUN", "TUR",
"TKM", "TUV", "UGA", "UKR", "ARE", "GBR", "USA", "URY", "UZB",
"VUT", "VEN", "VNM", "YEM", "ZMB", "ZWE"), Name = c("Afghanistan",
"Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda",
"Argentina", "Armenia", "Australia", "Austria", "Azerbaijan",
"Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
"Belize", "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina",
"Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burundi",
"Cambodia", "Cameroon", "Canada", "Cape Verde", "Central African Republic",
"Chad", "Chile", "China", "Colombia", "Comoros", "Congo (Brazzaville)",
"Congo (Kinshasa)", "Costa Rica", "Ivory Coast", "Croatia", "Cuba",
"Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica",
"Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea",
"Eritrea", "Estonia", "Ethiopia", "Fiji", "Finland", "France",
"Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Grenada",
"Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras",
"Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland",
"Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan",
"Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait",
"Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia",
"Libya", "Liechtenstein", "Lithuania", "Luxembourg", "North Macedonia",
"Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta",
"Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia",
"Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique",
"Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "New Zealand",
"Nicaragua", "Niger", "Nigeria", "Norway", "Oman", "Pakistan",
"Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
"Poland", "Portugal", "Qatar", "Romania", "Russia", "Rwanda",
"Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines",
"Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia",
"Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore",
"Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa",
"Spain", "Sri Lanka", "Sudan", "Suriname", "Eswatini", "Sweden",
"Switzerland", "Syria", "Tajikistan", "Tanzania", "Thailand",
"East Timor", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia",
"Turkey", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates",
"United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu",
"Venezuela", "Vietnam", "Yemen", "Zambia", "Zimbabwe"), vul_capacity_Rank_2021 = c(151L,
83L, 90L, NA, 156L, 120L, 61L, 63L, 25L, 19L, 71L, NA, 62L, 131L,
43L, 40L, 23L, 99L, 161L, 125L, 122L, 66L, 117L, 51L, 93L, 38L,
154L, 165L, 153L, 146L, 22L, 126L, 171L, 176L, 35L, 59L, 98L,
132L, 157L, 175L, 58L, 144L, 47L, 85L, 50L, 27L, 18L, 127L, NA,
95L, 87L, 57L, 94L, NA, 173L, 60L, 159L, 112L, 1L, 14L, 134L,
145L, 76L, 6L, 105L, 17L, 89L, 81L, 168L, 172L, 118L, 158L, 110L,
33L, 15L, 113L, 107L, 77L, 75L, 7L, 10L, 9L, 86L, 21L, 53L, 37L,
133L, NA, 123L, 28L, 30L, 42L, 139L, 46L, 91L, 149L, 166L, 136L,
NA, 70L, 16L, 92L, 163L, 150L, 45L, 82L, 160L, 32L, NA, 152L,
79L, 68L, NA, 84L, NA, 119L, 55L, 80L, 135L, 129L, 137L, NA,
138L, 3L, 4L, 88L, 169L, 140L, 5L, 96L, 115L, NA, 64L, 167L,
69L, 108L, 100L, 34L, 20L, 29L, 52L, 31L, 148L, NA, NA, NA, 114L,
NA, 101L, 111L, 130L, 97L, 54L, 164L, 24L, 41L, 26L, 143L, 174L,
104L, 8L, 116L, 155L, 72L, 128L, 12L, 2L, 109L, 67L, 141L, 73L,
142L, 162L, 106L, 78L, 65L, 36L, 44L, NA, 147L, 48L, 49L, 13L,
11L, 56L, 39L, 121L, 74L, 102L, 170L, 103L, 124L)), class = "data.frame", row.names = c(NA,
-192L))