Это должно сработать:
library(shiny)
library(shinyjs)
library(leaflet)
library(sf)
### Note had to download by hand as this did not work
## download.file(url = "http://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip",
## destfile = "TM_WORLD_BORDERS-0.3.zip")
## unzip( zipfile = "TM_WORLD_BORDERS-0.3.zip" )
world.borders <- read_sf( dsn = getwd(), layer = "TM_WORLD_BORDERS-0.3" )
world.borders <- world.borders[world.borders$NAME %in%
c("Australia", "United States", "Brazil",
"Ireland", "India", "Kenya"), ]
ui <- fluidPage(
useShinyjs(),
leafletOutput("mymap"),
selectInput(inputId = "country_choice",
label = "Select a country",
choices = c("Please Select..." = "", unique(world.borders$NAME)))
)
server <- function(input, output, session) {
runjs(glue::glue("$('.selectize-control').on('mouseenter', ",
"'.selectize-dropdown-content div', ",
"function() {{",
" Shiny.setInputValue('selected', $(this).data('value'));}}); ",
"$('.selectize-control').on('mouseleave', ",
"'.selectize-dropdown-content div', ",
"function() {{",
" Shiny.setInputValue('selected', null);}})"))
output$mymap <- renderLeaflet({
myBorders <- world.borders[world.borders$NAME == input$selected, ]
leaflet(options = leafletOptions(maxZoom = 18)) %>% addTiles() %>%
addPolygons(data = myBorders, fill = "#D24618", color = "blue")
})
}
shinyApp(ui, server)