[英]Edit map with “R for leaflet”
I have a script which allows me to generate a map with with "R for leaflet" : 我有一个脚本,可以使用“ R for leaflet”生成地图:
library(htmlwidgets)
library(raster)
library(leaflet)
# PATHS TO INPUT / OUTPUT FILES
projectPath = "path"
#imgPath = paste(projectPath,"data/cea.tif", sep = "")
#imgPath = paste(projectPath,"data/o41078a1.tif", sep = "") # bigger than standard max size (15431804 bytes is greater than maximum 4194304 bytes)
imgPath = paste(projectPath,"/test.tif", sep = "")
outPath = paste(projectPath, "/leaflethtmlgen.html", sep="")
# load raster image file
r <- raster(imgPath)
# reproject the image, if necessary
#crs(r) <- sp::CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
# color palette, which is interpolated ?
pal <- colorNumeric(c("#FF0000", "#666666", "#FFFFFF"), values(r),
na.color = "transparent")
# create the leaflet widget
m <- leaflet() %>%
addTiles() %>%
addRasterImage(r, colors=pal, opacity = 0.9, maxBytes = 123123123) %>%
addLegend(pal = pal, values = values(r), title = "Test")
# save the generated widget to html
# contains the leaflet widget AND the image.
saveWidget(m, file = outPath, selfcontained = FALSE, libdir = 'leafletwidget_libs')
My problem is that this is generating a html file and I need this map to be dyanamic. 我的问题是,这正在生成一个html文件,我需要这张地图是动态的。 For example, when a user click on some html button which is not integrate on the map, I want to add a rectangle on the map.
例如,当用户单击某个未在地图上集成的html按钮时,我想在地图上添加一个矩形。 Any solutions would be welcome...
任何解决方案都将受到欢迎...
Leaflet itself does not provide the interactive functionality you are looking for. Leaflet本身不提供您要查找的交互式功能。 One solution is to use shiny , which is a web application framework for R. From simple R code, it generates a web page, and runs R on the server-side to respond to user interaction.
一种解决方案是使用Shiny ,这是R的Web应用程序框架。它通过简单的R代码生成一个网页,并在服务器端运行R以响应用户交互。 It is well documented , has a gallery of examples, and a tutorial to get new users started.
它有充分的文档记录 ,有示例库 ,以及用于入门的入门教程 。
It works well with leaflet . 它与传单效果很好。 One of the examples on the shiny web site uses it, and also includes a link to the source code .
闪亮的网站上的示例之一使用它,并且还包含指向源代码的链接。
Actually, if simple showing/hiding of elements is enough, leaflet alone will suffice with the use of groups
. 实际上,如果简单地显示/隐藏元素就足够了,则仅使用传单就可以使用
groups
。 From the question it's not very clear how dynamic you need it to be. 从这个问题来看,还不清楚您需要它有多动态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.