rshinyr-leafletecharts4r

Leaflet Marker Cluster Not working with Echarts4r In Shiny


When I add an echart in shiny, the marker clusters in leaflet disappear. The map works fine when I remove the echart. Does this have something to do with htmlwidgets? Code is below.

library(leaflet)
library(dplyr)
library(shiny)
library(echarts4r)

# Create 3 map points -- 2 will be clustered

map_points <- bind_rows(c(location = 'A', lon = -122.4, lat = 37.8),
                        c(location = 'B', lon = -122.4, lat = 37.8),
                        c(location = 'C', lon = -118.2, lat = 34.0))

map_points$lon <- as.numeric(map_points$lon)
map_points$lat <- as.numeric(map_points$lat)


# Shiny

ui <- fluidPage(
  leafletOutput("mymap"),
  echarts4rOutput("myplot")
)

server <- function(input, output, session){
  output$mymap <- renderLeaflet({
    leaflet(map_points) %>%
      addProviderTiles("OpenStreetMap.Mapnik") %>%
      addCircleMarkers(lng = ~lon, 
                       lat = ~lat, 
                       group = "locations", 
                       layerId = ~location,
                       # adding clusterOptions removes the group in observeEvent
                       clusterOptions = markerClusterOptions() 
      )
  })
  
  observeEvent(input$mymap_marker_click, {
    print(input$mymap_marker_click)
  })
  
  output$myplot<-renderEcharts4r({
    ex2<-map_points%>%  
      e_charts(x = lon)
    
    ex2%>% e_scatter(lat)
  })
  
}

shinyApp(ui = ui, server = server)

Solution

  • Using updated repository will fix issue.

    remotes::install_github(“JohnCoene/echarts4r”)