leaflet-shiny and polylines

936 views
Skip to first unread message

Travis Hinkelman

unread,
Jun 7, 2014, 1:33:48 AM6/7/14
to shiny-...@googlegroups.com
I'm struggling to figure out how to add polylines to a map with leaflet-shiny. I've created a simple example that shows how the lines are not plotting correctly (see also Incorrect.png): 


I've also attached an image showing the lines correctly plotted with Mapbox.

I appreciate any suggestions. 

Thanks.
Incorrect.png
Correct.png

Joe Cheng

unread,
Jun 9, 2014, 2:52:50 PM6/9/14
to Travis Hinkelman, shiny-...@googlegroups.com
It appears that RJSONIO is truncating the significant digits down to 5 when converting the polyline coordinates to JSON. Setting options(digits=10) or whatever doesn't have an effect. I think we may need to address this in Shiny itself.


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Cheng

unread,
Jun 9, 2014, 3:04:45 PM6/9/14
to Travis Hinkelman, shiny-...@googlegroups.com
This is what it's like with RJSONIO modded to use digits=16 by default:
Inline image 1

It appears that some line segments are missing, which may or may not be a bug in the fork of leaflet-shiny--I'm not familiar with the addPolyline code.

José Manuel Rodríguez Sotelo

unread,
Jun 9, 2014, 4:44:55 PM6/9/14
to shiny-...@googlegroups.com
Hey,

I received a notification that you're using my fork of Joe's great package. I'm new to github, actually this was my first public collaboration, so I'm really excited about this. I added the javascript bindings for polyline, which are actually just a slight modification of the polygon bindings.

Look for polygon, in here:

Besides the RJSONIO truncating issue, I don't know what could be the reason of this problem. Could you try it changing your addPolyline for addPolygon? If you do that you can use Joe's Fork, and we can work it out from there.

José Manuel Rodríguez Sotelo

unread,
Jun 9, 2014, 4:46:06 PM6/9/14
to shiny-...@googlegroups.com, travis.h...@gmail.com
Hi,

Should I update Shiny to get this digits issue fixed?

JP

unread,
Jun 10, 2014, 8:34:56 AM6/10/14
to shiny-...@googlegroups.com, travis.h...@gmail.com
Hi,
 I had a similar digits issue, but using map$addCircle(). I found that if I stored the lat-long for the circle as character rather than numeric then it used the full precision. I don't understand why that works, but it may be worth a try.

Joe Cheng

unread,
Jun 10, 2014, 6:04:55 PM6/10/14
to JP, shiny-...@googlegroups.com, Travis Hinkelman
I haven't made the update to Shiny yet as we are just about to cut the final 0.10 release, and I feel this is slightly too risky to take without more testing. However, as soon as we have 0.10 publicly released then I'll add more digits in the Shiny call to toJSON.

In the meantime, if you want increased JSON precision now, you can use devtools to install from a branch where I've put the impending change:

devtools::install_github("rstudio/shiny", ref="feature/json-precision")


On Tue, Jun 10, 2014 at 5:34 AM, JP <john...@operamail.com> wrote:
Hi,
 I had a similar digits issue, but using map$addCircle(). I found that if I stored the lat-long for the circle as character rather than numeric then it used the full precision. I don't understand why that works, but it may be worth a try.

--
Reply all
Reply to author
Forward
0 new messages