library(shiny)
library(dplyr)
library(ggplot2)
library(readr)
library(htmltools)
library(leaflet)
library(geojsonio)
ui <- fluidPage(
selectInput (inputId = "medal", label = "Choose medal", list("Gold", "Silver", "Bronze", "Total")),
leafletOutput("Olymap"))
# Define server logic required to draw a histogram
server <- function(input, output) {
shapeurl <- "https://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json"
WorldCountry <- geojson_read(shapeurl, what = "sp")
Olympics<- read.csv("Olympics.csv")
groupcountry <- Olympics[, c(2, 10, 11, 12, 13)]
Oly_react <- reactive ({groupcountry %>%
group_by(Country) %>%
summarise(medalt = sum(input$medal))})
CountryOly <- reactive({left_join(data.frame(Name = WorldCountry$name), Oly_react(), by = c("Name" ="Country"))})
pat <- reactive({ CountryOly() %>% colorBin("viridis", domain = medalt)})
Pops <- reactive({ CountryOly() %>% paste("<strong>", Name, "</strong>", "<br/>",
"UrbanPop:", medalt)})
output$Olymap <-renderLeaflet({leaflet(WorldCountry) %>% addTiles() %>%
addPolygons(
fillColor = pat(CountryOly$medalt),
weight = 2,
opacity = 1,
color = "white",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 3,
color = "grey",
fillOpacity = 0.7,
bringToFront = TRUE),
popup = Pops())
})
}
# Run the application
shinyApp(ui = ui, server = server)
I'm trying to create an interactive map about the Olympic medals won by each country. I want to create a dropdown menu that allows the user to select "Gold","Silver", "Bronze", or "Total" and the map will change accordingly. But whenever I run the app, it keeps showingenter image description here Error'medalt' not found and I don't really know what's going on. I would really appreciate anyone who can help me with this problem.
", "UrbanPop:", CountryOly()$medalt)`. – stefan Oct 03 '21 at 07:08