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

Plotting route using rMaps and leaflet routing machine plugin #45

Closed
natalyoussef opened this issue Apr 5, 2014 · 22 comments
Closed

Plotting route using rMaps and leaflet routing machine plugin #45

natalyoussef opened this issue Apr 5, 2014 · 22 comments
Labels

Comments

@natalyoussef
Copy link

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
Copy link
Owner

ramnathv commented Apr 5, 2014

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

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

@natalyoussef
Copy link
Author

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
Copy link
Owner

ramnathv commented Apr 5, 2014

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
Copy link
Author

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
Copy link
Owner

ramnathv commented Apr 5, 2014

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

install.packages('base64enc')

@natalyoussef
Copy link
Author

Thank you! This solved the issue! :-)

@ramnathv
Copy link
Owner

ramnathv commented Apr 5, 2014

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
Copy link
Author

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
Copy link
Owner

ramnathv commented Apr 6, 2014

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

@natalyoussef
Copy link
Author

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
Copy link
Owner

ramnathv commented Apr 6, 2014

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
Copy link

pssguy commented Apr 6, 2014

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
Copy link
Owner

ramnathv commented Apr 6, 2014

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
Copy link

pssguy commented Apr 6, 2014

"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
Copy link
Owner

ramnathv commented Apr 6, 2014

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

@natalyoussef
Copy link
Author

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
Copy link

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

@dcooley
Copy link

dcooley commented Oct 27, 2015

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

@JiyingWen
Copy link

JiyingWen commented Aug 15, 2016

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
Copy link

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
Copy link

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

@jingwen-z
Copy link

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?

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

No branches or pull requests

7 participants