How?: Leaflet insert graphs (ggplot), buttons in a Popup

1,275 views
Skip to first unread message

Robert Lehr

unread,
Jul 17, 2015, 1:46:09 PM7/17/15
to shiny-...@googlegroups.com
I want to render a ggplot inside a Leaflet pop up. When I click a marker on my Leaflet map, I can make a pop up appear with some words like "Hi! I am a pop up!". 
I don't know why inserting interactive buttons, images, and graphs is not a feature. Instead of writing a string in the popup function as its output, I want to insert my ggplot object. 
Does anyone know how to do this, a workaround, or way to add this feature? It would be greatly appreciated!

Also, sadly, I am not familiar with java script or using leaflet outside of R.
I've looked through Leaflet Plug ins, stack exchange, github, and a few other sites, yet I can not find this feature for Leaflet in Shiny R. I may be looking in the wrong places.

Thanks for the help,
Robert

JP

unread,
Jul 17, 2015, 3:21:08 PM7/17/15
to shiny-...@googlegroups.com

I don't think it is possible at the moment. Right now I believe you can only render text in a popup. I don't know it that is a fundamental limitation of leaflet or if it is imposed by the leaflet R package. Hopefully someone more knowledgeable than I will be able to clarify.

Yihui Xie

unread,
Jul 19, 2015, 3:25:29 PM7/19/15
to JP, Robert Lehr, shiny-discuss
The fact that you can render arbitrary HTML content in a popup means
you can certainly insert images there, e.g. using <img
src="path/to/image" />. The only problem is that currently the HTML
content cannot be reactive like plotOutput() in shiny. There are no
problems with (pre-rendered) static images.

Regards,
Yihui

Robert Lehr

unread,
Jul 19, 2015, 3:37:59 PM7/19/15
to Yihui Xie, JP, shiny-discuss
Thanks! I could probably make is pseudo-reactive by saving an image as the output of a reactive function, so the path updates with new content. I'll try this tomorrow. 

Mahkameh Zare

unread,
Mar 1, 2016, 9:54:26 PM3/1/16
to Shiny - Web Framework for R
I have the same problem. Could you solve the issue? Is there any ways to solve it? It would be great if you could let me know about it...
Message has been deleted

MySchizo Buddy

unread,
Mar 2, 2016, 3:17:47 AM3/2/16
to Shiny - Web Framework for R
 I have used an actionButton with some javascript inisde the popup, It works very well
actionButton("selectLocationButton", "Select this Location", onclick = 'Shiny.onInputChange(\"selectLocationButton\",  Math.random())' )


Reply all
Reply to author
Forward
0 new messages