I want to create a flowmap using flowmapblue in Power BI using R code. You can se my code below. The map is not appearing..I don't know what I did wrong. Can anyone tell me what I did wrong? The code works fine in Rstudio and the map appears.
我想使用R代码在Power BI中使用flowmapblue创建一个流图。你可以在下面看到我的代码。地图没有出现。我不知道我做错了什么。谁能告诉我我做错了什么?代码在Rstudio中工作正常,并且显示地图。
The first 4 lines commented (#) are from power bi.
注释的前4行(#)来自Power bi。
# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:
# dataset <- data.frame(count, origin, dest, id, lat, lon)
# dataset <- unique(dataset)
# Paste or type your script code here:
library(htmlwidgets)
library(flowmapblue)
library(dplyr)
library(stringr)
flows <- dataset %>% select(count, origin, dest)
flows <- flows %>% group_by(origin, dest) %>% summarize(count = sum(count))
flows <- flows[!(flows$dest == "-1"),]
flows$count <- gsub(",", "\\.", flows$count)
locations <- dataset %>% select(id, lat, lon)
locations$lat <- gsub(",", "\\.", locations$lat)
locations$lon <- gsub(",", "\\.", locations$lon)
locations$lat <- as.numeric(locations$lat)
locations$lon <- as.numeric(locations$lon)
locations$id <- as.character(locations$id)
flowmapblue <- function(
locations, flows,
mapboxAccessToken = NULL,
clustering = TRUE,
animation = FALSE,
darkMode = TRUE
) {
# pass the data and settings using 'x'
x <- list(
locations = locations,
flows = flows,
mapboxAccessToken = mapboxAccessToken,
clustering = clustering,
animation = animation,
darkMode = darkMode
)
# create widget
htmlwidgets::createWidget(
name = 'flowmapblue',
x,
width = NULL,
height = NULL,
package = 'flowmapblue',
sizingPolicy = sizingPolicy(
padding = 0,
browser.padding = 0
)
)
}
mapboxAccessToken <- 'mytoken'
flowmapblue(locations, flows, mapboxAccessToken, darkMode=TRUE, clustering = TRUE, animation = FALSE)
更多回答
我是一名优秀的程序员,十分优秀!