ในแอป R Shiny เป็นไปได้ไหมที่จะมีแผนที่แผ่นพับที่เน้นรูปหลายเหลี่ยมที่ชี้โดย Select Item (ควรใช้งานได้เพียงแค่เลื่อนมูสไปเหนือรายการและไม่ต้องคลิก)
ในตัวอย่างที่ทำซ้ำได้ต่อไปนี้ ฉันต้องการให้แอป Shiny นี้ไฮไลต์รูปหลายเหลี่ยมที่ตรงกับตำแหน่งเคอร์เซอร์ของเมาส์ แต่ไม่ต้องคลิกเลย
library(shiny)
library(shinyjs)
library(leaflet)
library(sf)
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"),]
server <- function(input, output, session) {
output$mymap <- renderLeaflet({
leaflet(options = leafletOptions(maxZoom = 18)) %>% addTiles() %>%
addPolygons( data = world.borders, fill = "#D24618", color = "blue")
})
}
ui <- fluidPage(
leafletOutput("mymap"),
selectInput(inputId = "country_choice",label = "Select a country",choices = unique(world.borders$NAME))
)
shinyApp(ui, server)
ขอบคุณมาก !