r-spatial / mapedit

Interactive editing of spatial data in R
https://www.r-spatial.org/r/2019/03/31/mapedit_leafpm.html
Other
218 stars 33 forks source link

Using mapedit in loop #83

Closed MilanFischer closed 4 years ago

MilanFischer commented 5 years ago

Dear mapedit users, I am trying to make procedure in which I am loading raster maps and then get them to browser (Chrome) and interact with them (making polygons for further masking) using mapedit. I am running this in a batch using the for loop. However, I found that when loading within loop, mapedit is able to open correctly only every second map.

The core of this approach can be simplified in the following loop:

library(mapedit)
library(leaflet)

for(i in 1:10) {
New_Map<-leaflet()  %>%
  editMap(title=i)
flush.console()
}

You can see that you are not able to interact with maps 2,4,6,8 and 10.

If I am running that manually for each "i" without the for loop, then it works well. I am using R version 3.5.1. I run the code directly in the Rgui which leads that the mapedit is opened in web browser. I tried it also with R-studio where the same behavior was encountered. If I add a delay within the loop by e.g. Sys.sleep(5) then you can see that there is attempt to open maps 2,4,6,8 and 10 but it results in the following Chrome message "This site can’t be reached 127.0.0.1 refused to connect."

I would be thankful for any suggestion.

Milan

tim-salabim commented 5 years ago

Thanks! I think it is a problem of the app not being closed properly after hitting "Done". I will investigate

MilanFischer commented 5 years ago

I think so too. I actually noticed that if you close the Chrome window in standard way (by hitting ×) it works normally. Thanks for investigating that!

tim-salabim commented 5 years ago

Hi @MilanFischer thanks for your follow up mail. I have not investigated this any further so far. We are currently adding new features to mapedit and this has led to lower priorities of other open issues. Sorry

MilanFischer commented 5 years ago

Hi Tim, thanks for your response. I fully understand that. Cheers, Milan

noriegaedu commented 5 years ago

Hey guys, perhaps any of you or anybody has made any progress or made a workaround? I should mention that I use Edge as default browser,Milan's workaround doesn't work and this issue shows up with selectFeatures() function too.

Monika1992 commented 5 years ago

Hi all, we had a look at it together with @MilanFischer and found some kind of a solution. There is problem with user sessions, and with proper ending and starting of those. For simple use we adjusted editMap () function from edit.r. We ust adjusted lines 104-108 to:

    shiny::observeEvent(input$done, {
      crud()
      session$close()
    })

This prevents session to be closed unintentionally and also to not to be closed at all. It works for us, while using Chrome to edit data(did not test any other browsers). This is probably more a guide to where real problem is, as we are not experts in R and we also know almost nothing about how shiny etc. works. There is probably more R-way to solve it in general. But we are now able to cycle through data. Hope this helps :)

timelyportfolio commented 4 years ago

Everyone, thanks so much for the patience and the suggestions. I believe I have fixed. For reference, the onSessionEnded handler was preventing the full release/closure of the previous session. Cancelling the registered handler on done/cancel in selectMap and editMap seems to resolve the problem.

@MilanFischer, @tim-salabim, @Monika1992, @noriegaedu if possible, will you confirm this fix works for you?

Currently, the change is on master branch of Github remotes::install_github("timelyportfolio/mapedit").

timelyportfolio commented 4 years ago

@MilanFischer @tim-salabim @Monika1992 @noriegaedu was anyone able to test? If not, I'll consider complete and push to CRAN by end of weekend.

tim-salabim commented 4 years ago

Just tested with the example above. Seems to work! Again thanks @timelyportfolio for the great work! Before you submit to CRAN, I want to fix #110

MilanFischer commented 4 years ago

Hi Tim, I just tested the new version with the example as well as with the maps (the original purpose) and both works well. Thanks a lot for fixing that and for maintaining the package!