Quick question all. I have some data in sql server which i have loaded into RStudio. I have made a barchart for the data and now i am using leaflet library with the use of latitude and longitude to plot a point on the map. I want to be able to use popup to show a barchart in it when the user clicks on the point.
BarChart code (maybe this is a problem because i am using googleVis library so not sure if i can use this in the popup. but again this is the most appropriate bar graph i can make and need- other suggestions could be helpful as i am not a professional in R libraries yet)
Switzerland <- sqlQuery(con, "sql query")
SwitzerlandChart <- gvisBarChart(Switzerland, options = list(height=200))
For the graph plot the code is:
m <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addCircles(lng=8.498868, lat=46.9221, popup=paste(plot(SwitzerlandChart)))
When i run this code it opens a webpage to view my barplot. Then i run the following:
m #Prints the graph
This prints the graph with the point in the desired location but the popup shows me a webpage instead which also only i can open.
I want to be able to plot the bargraph inside the popup please.
Hope someone can help
This may be a little late too, but here is a full leaflet implementation. I first create the plot and then use the popupGraph function to add it in.
Here is the output.
Maybe a little late but here's a solution. The
addPopups()
function inlibrary(leaflet)
seems to be able to handle.svg
files. Therefore, you could simply save your plot usingsvg()
and then read it again usingreadLines()
. Here's a reproducible example usinglibrary(mapview)
:You will see that each popup is a scatterplot. As for a
leaflet
example, consider this:In case you need the plot to be interactive, you could have a look at
library(gridSVG)
which is able to produce interactive svg plots from e.g.lattice
orggplot2
plots.UPDATE:
library(mapview)
now has designated functionality for this:popupGraph
: to embed lattice, ggplot2 or interactive hatmlwidgets based plots.popupImage
: to embed local or remote (web) imagesThis is currently only available in the development version of mapview which can be installed with: