gpt4 book ai didi

How can I visualize flowmap with R code in Power BI?(如何在Power BI中可视化带有R代码的流程图?)

转载 作者:bug小助手 更新时间:2023-10-25 11:56:40 27 4
gpt4 key购买 nike



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)

更多回答
优秀答案推荐
更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com