ramnathv / rMaps

Interactive Maps from R
http://rmaps.github.io
389 stars 194 forks source link

Plotting route using rMaps and leaflet routing machine plugin #45

Closed natalyoussef closed 10 years ago

natalyoussef commented 10 years ago

Hi all!

I am new to using rMaps and leaflet. I would like to plot the route between two locations. The leaflet routing machine plugin allows us to do this (https://github.com/perliedman/leaflet-routing-machine). I am not quite sure how to use the functions addAssets() and setTemplate() to be able to use this plugin.

I have downloaded the "leaflet-routing-machine.min.js" file and saved in the same directory as my R code. I started playing a bit with the example that was given for rMaps. Here is my code so far:

question

I appreciate any help!! Thank you!

ramnathv commented 10 years ago

Here is a short writeup on how to use the routing plugin with rMaps.

https://gist.github.com/ramnathv/9998388

natalyoussef commented 10 years ago

The writeup was very helpful, especially to understand addAssets() and setTemplate()! Thank you very much! :)

Not sure if I should ask my question here, but the route still does not show on the map. The "afterScript" was not added to the html source code. Could you help me please understand where I might be messing up?

Thank you!

ramnathv commented 10 years ago

Do you have the dev version of rCharts installed. I added the afterScript argument to the templates in the dev version.

devtools::install_github("ramnathv/rCharts@dev")
natalyoussef commented 10 years ago

I followed your advice and this is the error I am obtaining on my Mac (with R 3.0.3)

question2

Is it possible that the issue is due to the newest version of R?

ramnathv commented 10 years ago

Ah okay. Another bug at my end. Just do this before you install the dev version

install.packages('base64enc')
natalyoussef commented 10 years ago

Thank you! This solved the issue! :-)

ramnathv commented 10 years ago

You are welcome. Note that this feature is still an experimental one. So use it with caution, especially if you plan to use it in production.

natalyoussef commented 10 years ago

Thank you for the heads-up. I will be using it as part of a short demo. I will keep following your updates regarding this feature. I am enjoying learning these new R tools!

ramnathv commented 10 years ago

Great. If you have feedback/comments, keep them coming. I always enjoy adding new features based on real use cases.

natalyoussef commented 10 years ago

Hi Ramnath, one more question:

I am trying to wrap the visualization of the map using "shiny". I am including the code you have shared with me within a server.R file using the function

output$map = renderMap({ map = Leaflet$new() .... [code with addAssets() and setTemplate()] .... map })

And then in the ui.R file using the function

mapOutput('map')

But I only see the map without the route. Is there something I am missing to add the new script to show in the web app?

Thank you!!

ramnathv commented 10 years ago

There is a bug in rCharts due to which renderMap and mapOutput don't work well with rMaps. I am aware of it and will push a fix.

pssguy commented 10 years ago

One more incentive to do so, for sure. This will really work well with Shiny

I'm using RStudio and clicking on map produces no browser-opening. Should I be doing something with the index.html file?

ramnathv commented 10 years ago

Are you clicking the object named map or are you running it in the console. If map were an rMaps object, it should open up in the RStudio Viewer.

Making this work with Shiny is easy, but requires some architectural changes to rCharts, which is why it is taking time. When I designed rCharts it was meant to be a standalone package. Now that other packages depend on it (like rMaps, rChartsExtra), I need to change some internal mechanisms that will allow more flexible use. This is currently high priority, so expect a fix very soon.

pssguy commented 10 years ago

"Click on the map to be taken to a full page interactive version, where you can see the routing directions as well"

The map does appear in RStudioViewer but clicking on it does not propogate a browser with directions

ramnathv commented 10 years ago

Got it. I will check what might be wrong with that.

natalyoussef commented 10 years ago

You have done an amazing job with the package rCharts! It is super useful. Having it work with shiny would be an awesome fix! I will be on the lookout for the updates!

Thank you very much, Ramnath!

manoj8385 commented 9 years ago

Hi Ramnathv...Hope you fix map to work in Shiny

dcooley commented 8 years ago

I posted this answer on StackOverflow that uses the routing with shiny. Does this answer some of the questions here?

JiyingWen commented 8 years ago

Hi Ramnath, I have the same problem that when wrap the code into shiny, the map is there but the route is not showing. Could you help with that? Thanks! @ramnathv

JiyingWen commented 8 years ago

Hi @tospig I followed your way but the style is a bit off as you said..Is there a way to not show the text? or move the text to the side of the map? Thanks!

JiyingWen commented 8 years ago

@tospig Hi your method doesn't work as well....it worked yesterday....Thanks for any help!

jingwen-z commented 7 years ago

Hi @ramnathv , thanks a lot for such detailed writeup on your gist, it's really helpful! However, I met a problem but didn't find the solution, could you bring me some idea? My computer is in WIN 7 system 64 bits, R is in version 3.4.0, R Studio is in version 1.0.143. I installed the package rMaps as you said in your github, used exactly the same codes as yours in your writeup, but didn't get the route between two positions. Do I need to do something else before run the script?