SymbolixAU / mapdeck

R interface to Deck.gl and Mapbox
https://symbolixau.github.io/mapdeck/articles/mapdeck.html
362 stars 40 forks source link

Click on layer does not return layer info in Shiny app with modules #387

Closed jacodevries closed 3 months ago

jacodevries commented 3 months ago

Describe the bug 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 has no response.

To Reproduce The following 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 )
        })

      }) 
  } 

Expected behaviour When running the app, a google map is opend with Mapdeck paths - clicking on a path should print the detail of the path to the console.

shinyApp(ui, server)

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)

Screenshots

image

image

image

image

Versions Having been using 0.3.4 without any problems. The issue only occurs when using 0.3.5.

Formatting use markdown to format code chunks

x <- c(1,2,3)
dcooley commented 3 months ago

how do I run the app with the modules?

jacodevries commented 3 months ago

Create files for ui.R, server.R and global.R in the root of your app folder. Create an R folder inside the app folder where the map_module.R script is saved.

If you open the ui.R in RStudio then you should be able to run the app. The map_module.R module will open automatically when the relevant page is opened.

dcooley commented 3 months ago

I clicked on a path and got this response

Screenshot 2024-06-23 at 9 28 52 AM

> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Australia/Melbourne
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sf_1.0-14            googleway_2.7.8      mapdeck_0.3.5        shinydashboard_0.7.2 shiny_1.8.1.1       

loaded via a namespace (and not attached):
 [1] bslib_0.7.0        htmlwidgets_1.6.4  devtools_2.4.5     remotes_2.4.2      processx_3.8.1     callr_3.7.3       
 [7] vctrs_0.6.5        tools_4.3.1        ps_1.7.5           generics_0.1.3     curl_5.2.1         tibble_3.2.1      
[13] proxy_0.4-27       fansi_1.0.5        pkgconfig_2.0.3    KernSmooth_2.23-21 assertthat_0.2.1   lifecycle_1.0.4   
[19] stringr_1.5.1      compiler_4.3.1     fontawesome_0.5.2  secret_1.1.0       httpuv_1.6.15      usethis_2.2.0     
[25] htmltools_0.5.8.1  class_7.3-22       sass_0.4.9         yaml_2.3.8         urlchecker_1.0.1   later_1.3.2       
[31] pillar_1.9.0       crayon_1.5.2       jquerylib_0.1.4    ellipsis_0.3.2     openssl_2.1.0      rsconnect_1.0.1   
[37] classInt_0.4-9     cachem_1.1.0       sessioninfo_1.2.2  mime_0.12          tidyselect_1.2.0   digest_0.6.35     
[43] stringi_1.8.2      purrr_1.0.2        dplyr_1.1.2        rprojroot_2.0.3    fastmap_1.2.0      grid_4.3.1        
[49] jsonify_1.2.3      cli_3.6.2          magrittr_2.0.3     pkgbuild_1.4.1     utf8_1.2.3         e1071_1.7-13      
[55] withr_3.0.0        prettyunits_1.1.1  promises_1.3.0     askpass_1.2.0      memoise_2.0.1      miniUI_0.1.1.1    
[61] profvis_0.3.8      rlang_1.1.3        Rcpp_1.0.12        xtable_1.8-4       glue_1.7.0         DBI_1.1.3         
[67] pkgload_1.3.2      rstudioapi_0.14    jsonlite_1.8.8     R6_2.5.1           fs_1.6.4           units_0.8-3 
Novus3-Admin commented 3 months ago

@dcooley Thank you very much for the feedback. I've spent hours if not days trying to resolve this issue and could not get it to work. The fact that you were able to run the app without any issue, confirmed my suspicion that there most be some other conflict in my R installation.

I've ended up formatting my laptop to ensure that I have a fresh installation of R and the packages as well as the databases used in my production app.

The issue resolved itself.

I can therefore unfortunately not provide any feedback on what could have caused the specific issue on my laptop.

Thank for a wonderful package. It is my go to for creating interactive maps with large datasets on Shiny.

dcooley commented 3 months ago

Glad it's all sorted for you; sometimes a complete reinstallation is the only thing that works :/

Are you @Novus3-Admin and @jacodevries the same person, and can I close this issue?

jacodevries commented 3 months ago

Dave

Apology. Did not realise that I was using both accounts to reply.

Yes, thanks. You can mark this as resolved.

Regards

Jaco

Get Outlook for iOShttps://aka.ms/o0ukef

Jaco de Vries Chief Operating Officer: Solutions | PrEng MEng

[https://novus3.co.za/wp-content/uploads/2021/09/Logo-Novus3_transparent.png]https://www.novus3.co.za/

http://www.novus3.co.zawww.novus3.co.zahttps://www.novus3.co.za | www.cp3.co.zahttps://www.cp3.co.za

E: @.*** M: +27 (0)82 729 1702 T: +27 (0)12 007 2564

[https://www.mail-signatures.com/signature-generator/img/templates/inclusive/fb.png]https://www.facebook.com/novus3consulting/ [https://www.mail-signatures.com/signature-generator/img/templates/inclusive/ln.png] https://www.linkedin.com/company/novus3/mycompany/?viewAsMember=true

Novus3(Pty)Ltd - Level 1 BBBEE contributor


From: Dave @.> Sent: Monday, June 24, 2024 12:53:53 AM To: SymbolixAU/mapdeck @.> Cc: Jaco de Vries @.>; Mention @.> Subject: Re: [SymbolixAU/mapdeck] Click on layer does not return layer info in Shiny app with modules (Issue #387)

Glad it's all sorted for you; sometimes a complete reinstallation is the only thing that works :/

Are you @Novus3-Adminhttps://github.com/Novus3-Admin and @jacodevrieshttps://github.com/jacodevries the same person, and can I close this issue?

— Reply to this email directly, view it on GitHubhttps://github.com/SymbolixAU/mapdeck/issues/387#issuecomment-2185348423, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKTFM24TBAW67UYDRQNMWFDZI5GYDAVCNFSM6AAAAABJPKSNVWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBVGM2DQNBSGM. You are receiving this because you were mentioned.Message ID: @.***>

Disclaimer

The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.

This email has been scanned for viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business. Providing a safer and more useful place for your human generated data. Specializing in; Security, archiving and compliance. To find out more visit the Mimecast website.