2017-11-14 5 views
1

Ich habe eine Karte, wo Symbole basierend auf Mouseover-Koordinaten geplottet werden. Als ich meine Markierungen von addCircles() zu addCircleMarkers änderte, hörte es jedoch auf zu funktionieren. Hier ist ein Codeausschnitt, der das Problem zeigt. Kommentieren Sie die Zeile addCircles, um zu sehen, wie sich das Verhalten ändert.R Shiny mouseover Verhalten unterscheidet sich für addCircles vs addCircleMarkers

library(shiny) 
library(leaflet) 

#create test data 
dataset <- structure(list(LATITUDE = c(37.09719065, 37.11063138, 37.1132722, 
           37.0749196, 37.02980937, 36.98644663, 
           36.94062755, 36.89560073, 36.85363852), 
        LONGITUDE = c(283.6828216, 283.7335099, 283.7892219, 
            283.813835, 283.812904, 283.7935855, 
            283.7740784, 283.7531182, 283.7280719), 
        ALTP = c(0.3963670049, 0.8659926907, 1.328491136, 
          1.855292223, 2.358125869, 2.792399835, 
          3.24886324, 3.708547366, 4.146854851)), 
        .Names = c("LATITUDE", "LONGITUDE", "ALTP"), 
        row.names = c(NA, 9L), 
        class = "data.frame") 


server <- function(input, output, session) { 

# create base map 
output$flightpath <- renderLeaflet({ 
leaflet() %>% addTiles() %>% setView(lng = 283.6828216, 
               lat = 36.94062755, 
               zoom = 10) 
    }) 

# add markers - this is where the problem is 
observe({ 
    leafletProxy("flightpath", data = dataset) %>% 
    addCircles(weight = 6, radius = 40) 
    #addCircleMarkers(weight = 6, radius = 6) 
}) 


# get map mouseover coordinates 
map_lat_lng <- reactive ({ 
    req(input$flightpath_shape_mouseover) 
    map_hover <- input$flightpath_shape_mouseover 
    x <- data.frame(map_hover$lat, map_hover$lng) 
    colnames(x) <- c("Latitude", "Longitude") 
    x 
}) 

# add icon to map 
observe({ 
    leafletProxy("flightpath", data = map_lat_lng()) %>% 
    clearGroup("hover") %>% 
    addMarkers(group = "hover") 
}) 
} 

ui <- fluidPage(leafletOutput("flightpath")) 

shinyApp(ui, server) 

Jede Hilfe, die dies herauszufinden würde geschätzt. Vielen Dank!

Antwort

1

Sie ändern es von einer Form zu einer Markierung, also müssen Sie die Objektkategorie ändern: flightpath_shape_mouseover sollte flightpath_marker_mouseover werden. Das sollte es beheben.

Verwandte Themen