微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Foundry 的代码工作簿中创建 Leaflet 地图

如何解决在 Foundry 的代码工作簿中创建 Leaflet 地图

有人使用 r-Leaflet 在 Code Workbook 中创建了传单地图吗?我有一个运行的功能脚本(也在 R 中进行了双重检查)但是我如何让它可视化然后在报告等中使用。我已经尝试了各种可能让它运行但没有成功的调整 - 任何想法>

leaflet_map <- function(map_data) {
    library(leaflet)
data<-map_data
# first cut the continuous variable into bins
# these bins are Now factors
data$Fill_rateLvl <- cut(data$Fill_rate,c(0,.5,0.6,0.7,0.8,0.9,1),include.lowest = T,labels = c('<50%','50-60%','60-70%','70-80%','80-90%','90-100%'))

# then assign a palette to this using colorFactor
# in this case it goes from red for the smaller values to yellow and green
# standard stoplight for bad,good,and best
FillCol <- colorFactor(palette = 'RdYlGn',data$Fill_rateLvl)

m<-leaflet() %>%
addTiles() %>%
 addProviderTiles(providers$CartoDB.Positron)%>%
  setView(lng = -0,lat = 50,zoom = 8) %>%
      addCircleMarkers(data = data,lat = ~lat,lng = ~long,color = ~FillCol(Fill_rateLvl),popup = data$Lead_employer,radius = ~sqrt(Fill_rate*50),group = 'Fill rate') %>%
                        addLegend('bottomright',pal = FillCol,values = data$Fill_rateLvl,title = 'Fill rate for next two weeks',opacity = 1)
return(NULL)
}

解决方法

我不熟悉代码工作簿中的 R,但在我看来,您需要将传单地图具体化为数据集,然后在某种地图兼容的 UI 中使用它。

例如,slate 有一个由传单支持的地图小部件。您可以在 yourfoundrystackhere.com/workspace/documentation/product/slate/map-widget

中找到相关文档和示例

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。