Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use raster in base map with editMap #114

Open
etiennebr opened this issue Aug 14, 2020 · 2 comments
Open

Use raster in base map with editMap #114

etiennebr opened this issue Aug 14, 2020 · 2 comments

Comments

@etiennebr
Copy link
Member

etiennebr commented Aug 14, 2020

I'm not sure I'm doing this correctly, but I would like to trace vectors on a raster using mapedit. I tried using raster and stars objects and they both produce different errors.

Here's a minimal reprex:

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.2, PROJ 6.2.1
library(mapview)
library(mapedit)

pol <- sf::st_as_sfc("POLYGON((0 0, 1.6 0, 1.6 1, 0 1, 0 0))", crs = 4326)
rs <- stars::st_as_stars(pol)
r <- raster::raster(matrix(1:4, 2, 2), crs = "+proj=longlat +datum=WGS84")

# editing on a polygon works fine
mapview(pol) %>%
  editMap()
#> Loading required namespace: leaflet.extras
#> 
#> Listening on http://127.0.0.1:6787

image
For vectors, it works well. Everything is there. There is a shiny error for stars objects:

mapview(rs) %>% 
  editMap()
#> Listening on http://127.0.0.1:6787
#> Warning: Error in addResourcePath: addResourcePath #> called with invalid prefix; please see documentation
#> 114: stop
#> 113: addResourcePath
#> 112: FUN
#> 111: lapply
#> 110: renderWidget
#> 109: transform
#> 108: func
#> 106: f
#> 105: Reduce
#> 96: do
#> 95: hybrid_chain
#> 94: origRenderFunc
#> 93: output$mapedit-edit-map
#> 13: shiny::runApp
#> 12: shiny::runGadget
#> 11: editMap.leaflet
#> 10: editMap.mapview
#> 8: function_list[[k]]
#> 6: freduce
#> 5: _fseq
#> 4: eval
#> 3: eval
#> 1: %>%

image

mapview(r) %>% 
  editMap()
#> Listening on http://127.0.0.1:6787
#> NULL
#> Warning messages:
#> 1: In showSRID(uprojargs, format = "PROJ", multiline = "NO") :
#>   Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs
#> 2: In showSRID(uprojargs, format = "PROJ", multiline = "NO") :
#>   Discarded datum WGS_1984 in CRS definition
#> 3: In showSRID(uprojargs, format = "PROJ", multiline = "NO") :
#>   Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs
#> 4: In showSRID(uprojargs, format = "PROJ", multiline = "NO") :
#>   Discarded datum WGS_1984 in CRS definition

image

With a raster object, there is no error, but the edit buttons are missing.
image

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.3 (2020-02-29)
#>  os       Ubuntu 18.04.4 LTS          
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_CA.UTF-8                 
#>  ctype    en_CA.UTF-8                 
#>  tz       America/Toronto             
#>  date     2020-08-14                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date       lib source                         
#>  abind         1.4-5      2016-07-21 [1] CRAN (R 3.6.3)                 
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.3)                 
#>  backports     1.1.8      2020-06-17 [1] CRAN (R 3.6.3)                 
#>  base64enc     0.1-3      2015-07-28 [1] CRAN (R 3.6.3)                 
#>  callr         3.4.3      2020-03-28 [1] CRAN (R 3.6.3)                 
#>  class         7.3-15     2019-01-01 [4] CRAN (R 3.5.2)                 
#>  classInt      0.4-3      2020-04-07 [1] CRAN (R 3.6.3)                 
#>  cli           2.0.2      2020-02-28 [1] CRAN (R 3.6.3)                 
#>  codetools     0.2-16     2018-12-24 [4] CRAN (R 3.5.2)                 
#>  colorspace    1.4-1      2019-03-18 [1] CRAN (R 3.6.3)                 
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.3)                 
#>  crosstalk     1.1.0.1    2020-03-13 [1] CRAN (R 3.6.3)                 
#>  DBI           1.1.0      2019-12-15 [1] CRAN (R 3.6.2)                 
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.5.2)                 
#>  devtools      2.3.1      2020-07-21 [1] CRAN (R 3.6.3)                 
#>  digest        0.6.25     2020-02-23 [1] CRAN (R 3.6.3)                 
#>  dplyr         1.0.1      2020-07-31 [1] CRAN (R 3.6.3)                 
#>  e1071         1.7-3      2019-11-26 [1] CRAN (R 3.6.2)                 
#>  ellipsis      0.3.1      2020-05-15 [1] CRAN (R 3.6.3)                 
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.1)                 
#>  fansi         0.4.1      2020-01-08 [1] CRAN (R 3.6.2)                 
#>  fastmap       1.0.1      2019-10-08 [1] CRAN (R 3.6.1)                 
#>  fs            1.5.0      2020-07-31 [1] CRAN (R 3.6.3)                 
#>  generics      0.0.2      2018-11-29 [1] CRAN (R 3.6.3)                 
#>  glue          1.4.1      2020-05-13 [1] CRAN (R 3.6.3)                 
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.6.3)                 
#>  htmltools     0.5.0      2020-06-16 [1] CRAN (R 3.6.3)                 
#>  htmlwidgets   1.5.1      2019-10-08 [1] CRAN (R 3.6.1)                 
#>  httpuv        1.5.4      2020-06-06 [1] CRAN (R 3.6.3)                 
#>  KernSmooth    2.23-16    2019-10-15 [4] CRAN (R 3.6.1)                 
#>  knitr         1.29       2020-06-23 [1] CRAN (R 3.6.3)                 
#>  later         1.1.0.1    2020-06-05 [1] CRAN (R 3.6.3)                 
#>  lattice       0.20-40    2020-02-19 [4] CRAN (R 3.6.2)                 
#>  leafem        0.1.3      2020-07-26 [1] CRAN (R 3.6.3)                 
#>  leaflet       2.0.3      2019-11-16 [1] CRAN (R 3.6.2)                 
#>  lifecycle     0.2.0      2020-03-06 [1] CRAN (R 3.6.3)                 
#>  lwgeom        0.2-5      2020-06-12 [1] CRAN (R 3.6.3)                 
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.3)                 
#>  mapedit     * 0.6.0      2020-02-02 [1] CRAN (R 3.6.3)                 
#>  mapview     * 2.9.0      2020-08-11 [1] CRAN (R 3.6.3)                 
#>  memoise       1.1.0.9000 2020-01-30 [1] Github (hadley/memoise@58d3972)
#>  mime          0.9        2020-02-04 [1] CRAN (R 3.6.3)                 
#>  munsell       0.5.0      2018-06-12 [1] CRAN (R 3.5.2)                 
#>  pillar        1.4.6      2020-07-10 [1] CRAN (R 3.6.3)                 
#>  pkgbuild      1.1.0      2020-07-13 [1] CRAN (R 3.6.3)                 
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 3.6.1)                 
#>  pkgload       1.1.0      2020-05-29 [1] CRAN (R 3.6.3)                 
#>  png           0.1-7      2013-12-03 [1] CRAN (R 3.6.3)                 
#>  prettyunits   1.1.1      2020-01-24 [1] CRAN (R 3.6.2)                 
#>  processx      3.4.3      2020-07-05 [1] CRAN (R 3.6.3)                 
#>  promises      1.1.1      2020-06-09 [1] CRAN (R 3.6.3)                 
#>  ps            1.3.4      2020-08-11 [1] CRAN (R 3.6.3)                 
#>  purrr         0.3.4      2020-04-17 [1] CRAN (R 3.6.3)                 
#>  R6            2.4.1      2019-11-12 [1] CRAN (R 3.6.2)                 
#>  raster        3.3-13     2020-07-17 [1] CRAN (R 3.6.3)                 
#>  Rcpp          1.0.5      2020-07-06 [1] CRAN (R 3.6.3)                 
#>  remotes       2.2.0      2020-07-21 [1] CRAN (R 3.6.3)                 
#>  rgdal         1.5-16     2020-08-07 [1] CRAN (R 3.6.3)                 
#>  rlang         0.4.7      2020-07-09 [1] CRAN (R 3.6.3)                 
#>  rmarkdown     2.3        2020-06-18 [1] CRAN (R 3.6.3)                 
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.3)                 
#>  s2            1.0.2      2020-08-03 [1] CRAN (R 3.6.3)                 
#>  satellite     1.0.2      2019-12-09 [1] CRAN (R 3.6.2)                 
#>  scales        1.1.1      2020-05-11 [1] CRAN (R 3.6.3)                 
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.5.2)                 
#>  sf          * 0.9-6      2020-08-10 [1] local                          
#>  shiny         1.5.0      2020-06-23 [1] CRAN (R 3.6.3)                 
#>  sp            1.4-2      2020-05-20 [1] CRAN (R 3.6.3)                 
#>  stars         0.4-3      2020-07-08 [1] CRAN (R 3.6.3)                 
#>  stringi       1.4.6      2020-02-17 [1] CRAN (R 3.6.3)                 
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.5.2)                 
#>  testthat      2.3.2      2020-03-02 [1] CRAN (R 3.6.3)                 
#>  tibble        3.0.3      2020-07-10 [1] CRAN (R 3.6.3)                 
#>  tidyselect    1.1.0      2020-05-11 [1] CRAN (R 3.6.3)                 
#>  units         0.6-7      2020-06-13 [1] CRAN (R 3.6.3)                 
#>  usethis       1.6.1      2020-04-29 [1] CRAN (R 3.6.3)                 
#>  vctrs         0.3.2      2020-07-15 [1] CRAN (R 3.6.3)                 
#>  webshot       0.5.2      2019-11-22 [1] CRAN (R 3.6.2)                 
#>  withr         2.2.0      2020-04-20 [1] CRAN (R 3.6.3)                 
#>  wk            0.3.2      2020-08-03 [1] CRAN (R 3.6.3)                 
#>  xfun          0.16       2020-07-24 [1] CRAN (R 3.6.3)                 
#>  xtable        1.8-4      2019-04-21 [1] CRAN (R 3.5.2)                 
#>  yaml          2.2.1      2020-02-01 [1] CRAN (R 3.6.3)                 
#> 
#> [1] /home/etienne/R/x86_64-pc-linux-gnu-library/3.6
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
@timelyportfolio
Copy link
Contributor

timelyportfolio commented Aug 18, 2020

@tim-salabim Have you tested mapview + stars with shiny? I see the addResourcePath error with any mapview + stars in shiny. Perhaps this is related to r-spatial/mapview#308.

library(sf)
library(mapview)
library(mapedit)

pol <- sf::st_as_sfc("POLYGON((0 0, 1.6 0, 1.6 1, 0 1, 0 0))", crs = 4326)

rs <- stars::st_as_stars(pol)

r <- raster::raster(matrix(1:4, 2, 2), crs = "+proj=longlat +datum=WGS84")

library(shiny)
shinyApp(
  mapviewOutput('mv'),
  function(input,output,session) {
    output$mv <- renderMapview({
      mapview(rs)
    }) 
  }
)

I traced the error to this line in Shiny. The problem is that the path contains spaces. addResourcePath documentation says

#' @param prefix The URL prefix (without slashes). Valid characters are a-z,
#'   A-Z, 0-9, hyphen, period, and underscore. For example, a value of 'foo'
#'   means that any request paths that begin with '/foo' will be mapped to the
#'   given directory.

The prefix check is in these lines.

To tie it all together with @etiennebr example.

> paste(mapview(rs)@map$dependencies[[11]]$name, "-", dependency$version, 
+             sep = "")
[1] "rs - 1-0.0.1"

...or the actual error

shiny::createWebDependency(mapview(rs)@map$dependencies[[11]])

@tim-salabim
Copy link
Member

No I haven't. I will try to debug soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants