我正在尝试使用r显示传单Map(我不能使用shinyapp软件包)。我想在传单标题(或Map中的任何地方)中显示选定点的列平均值,如下图所示:
这是我的尝试:
library(dplyr)
library(leaflet)
library(DT)
library(crosstalk)
data_2 <- data.frame(ID=c(1:8),
Name1 = c("A", "A", "A", "C", "B", "B", "A", "B"),
Name2 = c("a", "b", "b", "a", "b", "a", "b", "c"),
Value1 = c(12,43,54,34,23,77,44,22),
Value2 = c(6,5,2,7,5,6,4,3),
Lat = c(51.1, 51.6, 57.3, 52.4, 56.3, 54.3, 60.4, 49.2),
Lon = c(5, -3, -2, -1, 4, 3, -5, 0))
data_2<-data_2 %>%
mutate(
lab_DB = case_when(
Name1 == unique(data_2$Name1)[1] ~ "blue",
Name1 == unique(data_2$Name1)[2] ~ "green",
Name1 == unique(data_2$Name1)[3] ~ "red"
)
)
data_2$ID <- as.character(data_2$ID)
sdf <- SharedData$new(data_2, ~data_2$ID)
ltlf5<- leaflet(sdf) %>%
#addProviderTiles(providers$CartoDB.Positron) %>%
addTiles() %>%
addCircleMarkers(
lng = ~Lat,
lat = ~Lon,
group = ~Name1,popup = ~paste(Name1, ' <br/> ',
Name2,' <br/> ' ),
color =~lab_DB ,
radius = 3
) %>%
addLayersControl(
overlayGroups = c('A','B','C')
,options = layersControlOptions(collapsed = FALSE)
) %>%
addLegend(
position = 'bottomleft',
labels = c('Group A','Group B','Group C'),
colors = c("blue","red", "green"),
title = "number of observation"
)
bscols(ltlf5 ,
datatable(sdf , width = "100%",editable=TRUE,caption = paste("mean of Value1:",mean(sdf$data()$Value1)))
)
但不幸的是,它显示的是选定点的“value1”列的平均值,而不是“value1”列的平均值。那么怎么做呢?
暂无答案!
目前还没有任何答案,快来回答吧!