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

Is there a way of flushing the old data from $finished when using singleFeature=TRUE mapedit in a Shiny app? #106

Closed
jennet opened this issue Oct 15, 2019 · 9 comments

Comments

@jennet
Copy link

jennet commented Oct 15, 2019

I have a shiny app that uses mapedit to allow the user to draw around an area of the country they are interested in, and then the app gets placemarks from a number of different datasets. I have set mapedit to singleFeature=TRUE when creating the map, and I found that regardless of this, the app was returning data from "old" drawn features. I've narrowed this down to the fact that each time the user draws a new area, this gets returned (along with old areas, even though they have been deleted) in the $finished values.

e.g.

  1. user draws area on map - output shows Simple feature collection with 1 feature and 2 fields
  2. user draws second area on map - map only shows single feature as set up in options - output shows Simple feature collection with 2 features and 2 fields
  3. user uses delete button "clear all" - output shows Simple feature collection with 1 feature and 2 fields, as only last feature is deleted.

Basically - is there a way to force mapedit to only retain the most recently drawn feature if the map is set to single feature only? If not, I'll have to add to my code to only retrieve data for the last feature (as shown on verbatimTextOutput("feature_of_interest") in the code below), but I think perhaps my problem is that I've not set up mapedit correctly, or I'm missing something else obvious.

I've done a simple version showing this here:

library(shiny)
library(mapedit)
library(leaflet)
library(leaflet.extras)
library(tidyverse)

ui <- fluidPage(

    titlePanel("MapEdit"),

    sidebarLayout(
        sidebarPanel(
            editModUI("selectorMap")
        ),

        mainPanel(
            verbatimTextOutput("finished"),
            verbatimTextOutput("feature_of_interest")
        )
    )
)

server <- function(input, output, session) {
    
    eng_centre_lat <- 52.3555
    eng_centre_long <- -1.7743
    baseMap <- leaflet() %>% 
        addProviderTiles(providers$OpenStreetMap) %>%
        addResetMapButton() %>%
        addSearchOSM() %>%
        setView(lat = eng_centre_lat, lng = eng_centre_long, zoom = 7) 
    
    editableBaseMap <- baseMap %>%
        addDrawToolbar(
            polylineOptions = FALSE,
            circleOptions = FALSE,
            circleMarkerOptions = FALSE,
            markerOptions = FALSE,
            editOptions = editToolbarOptions(),
            singleFeature = TRUE)
    
    ns <- shiny::NS("selectorMap") 
    drawn <- callModule(editMod, "selectorMap", editableBaseMap)

    output$finished <- renderPrint({
        req(drawn()$finished)
        drawn()$finished
    })
    output$feature_of_interest <- renderPrint({
        req(drawn()$finished)
        result <- drawn()$finished
        result[nrow(result),]
    })
   
}

# Run the application 
shinyApp(ui = ui, server = server)

@jennet jennet changed the title Is there a way of flushing the old data from $finished when using mapedit in a Shiny app? Is there a way of flushing the old data from $finished when using singleFeature=TRUE mapedit in a Shiny app? Oct 15, 2019
@fawda123
Copy link

fawda123 commented Jan 8, 2020

I also came across this issue today, it would be great to have a fix.

@eastcoasting
Copy link

eastcoasting commented Mar 30, 2020

I also have struggled to solve this issue, the same issue occurs in the quakes r-spatial shiny example.

After using the mapedit select polygons tool the plot successfully renders; however, if you attempt to clear the selected polygons using the delete tool, the plot caches the intersected values and fails to clear the plot. Is there any way to force the delete tool to flush these values? If you attempt to delete multiple polygons at the same time there is also an additional error "argument is of length zero".

mapedit

This would be extremely useful for shiny apps that use the mapedit tool to select polygons/points and reference a secondary dataset to generate a plot. As it stands I cannot determine how to cleanly implement this without a clear plot/df button.

@eastcoasting
Copy link

@tim-salabim @timelyportfolio Is it likely we will see a fix for this problem in coming releases? I would love to use mapedit for my application, but have yet to find any evidence in other forums this problem is solvable without reworking the source code. Thanks in advance!

@timelyportfolio
Copy link
Contributor

@eastcoasting I should have some time this week/weekend to take a look. Thanks for the patience.

@timelyportfolio
Copy link
Contributor

@eastcoasting @fawda123 @jennet @tim-salabim I think I found a solution in 027b2da. Please test if you have a moment remotes::install_github("r-spatial/mapedit"). Thanks again for reporting.

@fawda123
Copy link

fawda123 commented Apr 8, 2020

@timelyportfolio works for me, thanks for the fix!

- Session info ------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.6.1 (2019-07-05)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United States.1252  
 ctype    English_United States.1252  
 tz       America/New_York            
 date     2020-04-08                  

- Packages ----------------------------------------------------------------------------------------------------------------------------------------------------
 package        * version  date       lib source                              
 assertthat       0.2.1    2019-03-21 [1] CRAN (R 3.6.1)                      
 backports        1.1.6    2020-04-05 [1] CRAN (R 3.6.1)                      
 bitops           1.0-6    2013-08-17 [1] CRAN (R 3.6.0)                      
 broom            0.5.2    2019-04-07 [1] CRAN (R 3.6.1)                      
 callr            3.4.3    2020-03-28 [1] CRAN (R 3.6.3)                      
 cellranger       1.1.0    2016-07-27 [1] CRAN (R 3.6.1)                      
 class            7.3-15   2019-01-01 [2] CRAN (R 3.6.1)                      
 classInt         0.4-3    2020-04-07 [1] CRAN (R 3.6.1)                      
 cli              2.0.2    2020-02-28 [1] CRAN (R 3.6.3)                      
 colorspace       1.4-1    2019-03-18 [1] CRAN (R 3.6.1)                      
 crayon           1.3.4    2017-09-16 [1] CRAN (R 3.5.1)                      
 crosstalk        1.1.0.1  2020-03-13 [1] CRAN (R 3.6.1)                      
 curl             4.3      2019-12-02 [1] CRAN (R 3.6.1)                      
 data.table       1.12.8   2019-12-09 [1] CRAN (R 3.6.1)                      
 DBI              1.1.0    2019-12-15 [1] CRAN (R 3.6.1)                      
 desc             1.2.0    2018-05-01 [1] CRAN (R 3.5.1)                      
 devtools         2.2.1    2019-09-24 [1] CRAN (R 3.6.1)                      
 digest           0.6.25   2020-02-23 [1] CRAN (R 3.6.1)                      
 dplyr          * 0.8.5    2020-03-07 [1] CRAN (R 3.6.1)                      
 e1071            1.7-3    2019-11-26 [1] CRAN (R 3.6.1)                      
 ellipsis         0.3.0    2019-09-20 [1] CRAN (R 3.6.1)                      
 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)                      
 flexdashboard  * 0.5.1.1  2018-06-29 [1] CRAN (R 3.6.1)                      
 forcats        * 0.4.0    2019-02-17 [1] CRAN (R 3.6.1)                      
 fs               1.3.1    2019-05-06 [1] CRAN (R 3.6.1)                      
 generics         0.0.2    2018-11-29 [1] CRAN (R 3.6.1)                      
 ggplot2        * 3.3.0    2020-03-05 [1] CRAN (R 3.6.1)                      
 glue             1.4.0    2020-04-03 [1] CRAN (R 3.6.1)                      
 gtable           0.3.0    2019-03-25 [1] CRAN (R 3.6.1)                      
 haven            2.1.1    2019-07-04 [1] CRAN (R 3.6.1)                      
 hms              0.5.3    2020-01-08 [1] CRAN (R 3.6.2)                      
 htmltools        0.4.0    2019-10-04 [1] CRAN (R 3.6.1)                      
 htmlwidgets      1.5.1    2019-10-08 [1] CRAN (R 3.6.1)                      
 httpuv           1.5.2    2019-09-11 [1] CRAN (R 3.6.1)                      
 httr             1.4.1    2019-08-05 [1] CRAN (R 3.6.1)                      
 jsonlite         1.6.1    2020-02-02 [1] CRAN (R 3.6.1)                      
 KernSmooth       2.23-15  2015-06-29 [2] CRAN (R 3.6.1)                      
 knitr            1.25     2019-09-18 [1] CRAN (R 3.6.1)                      
 later            1.0.0    2019-10-04 [1] CRAN (R 3.6.1)                      
 lattice          0.20-38  2018-11-04 [2] CRAN (R 3.6.1)                      
 lazyeval         0.2.2    2019-03-15 [1] CRAN (R 3.6.1)                      
 leaflet        * 2.0.3    2019-11-16 [1] CRAN (R 3.6.1)                      
 leaflet.extras * 1.0.0    2018-04-21 [1] CRAN (R 3.6.2)                      
 lifecycle        0.2.0    2020-03-06 [1] CRAN (R 3.6.1)                      
 lubridate        1.7.8    2020-04-06 [1] CRAN (R 3.6.1)                      
 magrittr         1.5      2014-11-22 [1] CRAN (R 3.5.1)                      
 mapedit        * 0.6.1    2020-04-08 [1] Github (r-spatial/mapedit@eaf6a57)  
 memoise          1.1.0    2017-04-21 [1] CRAN (R 3.5.1)                      
 mime             0.9      2020-02-04 [1] CRAN (R 3.6.1)                      
 modelr           0.1.5    2019-08-08 [1] CRAN (R 3.6.1)                      
 munsell          0.5.0    2018-06-12 [1] CRAN (R 3.5.1)                      
 nlme             3.1-140  2019-05-12 [2] CRAN (R 3.6.1)                      
 packrat          0.5.0    2018-11-14 [1] CRAN (R 3.6.1)                      
 pillar           1.4.3    2019-12-20 [1] CRAN (R 3.6.2)                      
 pkgbuild         1.0.6    2019-10-09 [1] CRAN (R 3.6.1)                      
 pkgconfig        2.0.3    2019-09-22 [1] CRAN (R 3.6.1)                      
 pkgload          1.0.2    2018-10-29 [1] CRAN (R 3.6.1)                      
 plotly         * 4.9.2    2020-02-12 [1] CRAN (R 3.6.3)                      
 prettyunits      1.1.1    2020-01-24 [1] CRAN (R 3.6.1)                      
 processx         3.4.2    2020-02-09 [1] CRAN (R 3.6.2)                      
 promises         1.1.0    2019-10-04 [1] CRAN (R 3.6.1)                      
 ps               1.3.2    2020-02-13 [1] CRAN (R 3.6.2)                      
 purrr          * 0.3.3    2019-10-18 [1] CRAN (R 3.6.1)                      
 R6               2.4.1    2019-11-12 [1] CRAN (R 3.6.1)                      
 RColorBrewer     1.1-2    2014-12-07 [1] CRAN (R 3.5.0)                      
 Rcpp             1.0.4    2020-03-17 [1] CRAN (R 3.6.1)                      
 RCurl            1.98-1.1 2020-01-19 [1] CRAN (R 3.6.2)                      
 reactable      * 0.1.0.1  2020-02-29 [1] CRAN (R 3.6.3)                      
 readr          * 1.3.1    2018-12-21 [1] CRAN (R 3.6.1)                      
 readxl           1.3.1    2019-03-13 [1] CRAN (R 3.6.1)                      
 remotes          2.1.0    2019-06-24 [1] CRAN (R 3.6.1)                      
 rlang            0.4.5    2020-03-01 [1] CRAN (R 3.6.3)                      
 rmarkdown        1.16     2019-10-01 [1] CRAN (R 3.6.1)                      
 rprojroot        1.3-2    2018-01-03 [1] CRAN (R 3.5.1)                      
 rsconnect        0.8.15   2019-07-22 [1] CRAN (R 3.6.1)                      
 rstudioapi       0.11     2020-02-07 [1] CRAN (R 3.6.3)                      
 rvest            0.3.5    2019-11-08 [1] CRAN (R 3.6.2)                      
 scales           1.1.0    2019-11-18 [1] CRAN (R 3.6.1)                      
 sessioninfo      1.1.1    2018-11-05 [1] CRAN (R 3.6.1)                      
 sf             * 0.9-1    2020-04-06 [1] CRAN (R 3.6.1)                      
 shiny            1.4.0.2  2020-03-13 [1] CRAN (R 3.6.3)                      
 shinydashboard * 0.7.1    2018-10-17 [1] CRAN (R 3.6.1)                      
 shinyWidgets   * 0.4.9    2019-09-10 [1] CRAN (R 3.6.1)                      
 stringi          1.4.6    2020-02-17 [1] CRAN (R 3.6.2)                      
 stringr        * 1.4.0    2019-02-10 [1] CRAN (R 3.6.1)                      
 tbeptools      * 0.0.1    2020-04-06 [1] Github (tbep-tech/tbeptools@53df5d6)
 testthat         2.3.2    2020-03-02 [1] CRAN (R 3.6.3)                      
 tibble         * 3.0.0    2020-03-30 [1] CRAN (R 3.6.1)                      
 tidyr          * 1.0.2    2020-01-24 [1] CRAN (R 3.6.1)                      
 tidyselect       1.0.0    2020-01-27 [1] CRAN (R 3.6.1)                      
 tidyverse      * 1.2.1    2017-11-14 [1] CRAN (R 3.6.1)                      
 units            0.6-6    2020-03-16 [1] CRAN (R 3.6.1)                      
 usethis          1.5.1    2019-07-04 [1] CRAN (R 3.6.1)                      
 vctrs            0.2.4    2020-03-10 [1] CRAN (R 3.6.3)                      
 viridisLite      0.3.0    2018-02-01 [1] CRAN (R 3.5.1)                      
 withr            2.1.2    2018-03-15 [1] CRAN (R 3.5.1)                      
 xfun             0.12     2020-01-13 [1] CRAN (R 3.6.2)                      
 xml2             1.3.0    2020-04-01 [1] CRAN (R 3.6.1)                      
 xtable           1.8-4    2019-04-21 [1] CRAN (R 3.6.1)                      
 yaml             2.2.1    2020-02-01 [1] CRAN (R 3.6.1)                      

[1] C:/Users/Marcus/R/win-library/3.6
[2] C:/Program Files/R/R-3.6.1/library

@eastcoasting
Copy link

@timelyportfolio Works for me thank you very much!

@timelyportfolio
Copy link
Contributor

I'll close the issue and hopefully submit to CRAN by end of weekend. Thanks again to all who participated and helped.

@pkmkp
Copy link

pkmkp commented Mar 15, 2021

@timelyportfolio I came across this problem recently. Installing the package from github did work for me, but not from CRAN (as of October 29, 2020).

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

5 participants