rshinymapdeck

Mapdeck 0.3.5 click on layer does not return layer info in Shiny app with modules


After upgrading to mapdeck 0.3.5, the click on layer functionality of mapdeck in combination with Googlemaps (googleway library) does not return any results in a Shiny app with modules. Clicking on a path layer has no response. The expected behaviour is that clicking on the path layer should return the attributes of the path on which the user clicked.

The following shiny modular app reproduces the problem on a MacBook Pro (M1), using Chrome and mapdeck 0.3.5.

------global.R-------------------

library(shiny)
library(shinydashboard)
library(mapdeck)
library(googleway)
library(sf)
------UI.R-------------------

# App UI
dashboardPage(
## header
    dashboardHeader(
    title = "Mapdeck Reprex"),

## Sidebar
  dashboardSidebar(
    menuSubItem(
      "Googlemap",
      tabName = "Map",
      icon = icon("map", lib = "font-awesome")
    )
  ),
  
## Body
  dashboardBody(
    tabItems(
      tabItem(
        tabName = "Map",
        MapdeckGooglewayMap_UI("MapdeckGooglewayMap")
      )
    )
  )
)
------server.R-------------------

App Server
function(input, output, session) {
  MapdeckGooglewayMap_Server(
    "MapdeckGooglewayMap"
  )
} 
------map_module.R--------------

# 1. Module UI =============================================================
MapdeckGooglewayMap_UI <- 
  function(id, label = "GooglewayMap"){
    # 1. Define UI ------------------
    fluidPage(
      
      fluidRow(
        box(
          title = "Spatial analysis and map controls",
          google_mapOutput(outputId = NS(id, "map"))
     
        ) ## end of box
      ) ## end of fluid_row
    ) ## end of fluidpage
  }
2. Module Server ======================================================================
MapdeckGooglewayMap_Server <-
function(id){

moduleServer(
  id, 
  function(input, output, session
  ){

    ## initialise a map
    output$map <- renderGoogle_map({
      google_map(key = Sys.getenv("GoogleAPIkey")) %>%
        mapdeck::add_dependencies() %>%
        mapdeck::add_path(
          data = roads[1:3, ],
          stroke_width = 5,
          id = "FQID"
        )
    })
    
    ## use an observer to respond to the click event.
    observeEvent({input$map_path_click},{
      print( input$map_path_click )
      
      js <- input$map_path_click
      lst <- jsonlite::fromJSON( js )
      print( lst )
    })
    
  }) 
}

Chrome's dev tools shows the following error: enter image description here

enter image description here

enter image description here

The app worked fine with mapdeck 0.3.4.

The functionality works when a shiny app without modules is used:

Below is the code for a single app version which is a modified version of the Shiny Returning data example at https://symbolixau.github.io/mapdeck/articles/tips_tricks.html. The example has been changed to use Google Maps instead of Mapdeck maps.

---- single app version which does work -------

library(shiny)
library(shinydashboard)
library(mapdeck)
library(googleway)
library(sf)

ui <- dashboardPage(
  dashboardHeader()
  , dashboardSidebar(
  #   actionButton(inputId = "roads", label = "roads")
  )
  , dashboardBody(
    google_mapOutput(outputId = "map")
  )
)

server <- function(input, output) {
  
  output$map <- renderGoogle_map({
    google_map(key = Sys.getenv("GoogleAPIkey")) %>%
      mapdeck::add_dependencies() %>%
      mapdeck::add_path(
        data = roads[1:3, ],
        stroke_width = 5,
        id = "FQID"
      )
  })
  
  ## use an observer to respond to the click event.
  observeEvent({input$map_path_click},{
    print( input$map_path_click )
    
    js <- input$map_path_click
    lst <- jsonlite::fromJSON( js )
    print( lst )
  })
}

shinyApp(ui, server)

Any suggestions to resolve this issue will be appreciated.


Solution

  • Dave Cooley of SymbolixAU kindly reviewed my reprex and could not replicate the issue. This led me to conclude that the issue was caused by some conflict in my R installation or the packages used in my production Shiny App. After many days of trying to trap the error, I ended up formatting my laptop to force a fresh installation.

    That resolved the issue.

    Unfortunately I cannot provide details of what caused this specific issue.