首页 > 解决方案 > 在 Power BI 中的 R 中使用 GoogleVis

问题描述

我正在尝试复制这些:

https://radacad.com/interactive-map-using-r-and-power-bi-create-custom-visual-part-1

是否可以在 Power BI 的 R Script Visual 中使用 R Plotly 库?

Plotly 的问题在于,对于我的数据集,即使我在 R 中编译它也很慢。需要几分钟。所以,我决定用非常快的 googleVis 替换它(我在 R 中打开任何其他交互式甘特图)。

这是我在 R 中的代码:

 df <- data.frame(Values)
library("googleVis")

 #df$Project.Name <- toString(df$Project.Name)
df$Processed_start_date_cut <- as.Date(df$Processed_start_date_cut)
df$Processed_End_date <- as.Date(df$Processed_End_date)
#df$Milestone <- toString(df$Milestone)

 g <- gvisTimeline(data=df, 
              rowlabel="Project.Name",
              barlabel="Milestones",
              start="Processed_start_date_cut", 
              end="Processed_End_date",
              options=list(timeline="{rowLabelStyle:{fontName:'Helvetica', 
                           fontSize:10, color:'#603913'},
                           barLabelStyle:{fontName:'Garamond', 
                           fontSize:12}}",
                           backgroundColor='#ffd', 
                           height=350 ))
 cat(g$html$chart, file="out.html")

我已经在 R 中尝试过,效果很好。在 BI 中这是第一次工作,但是当我更改任何过滤器时,这个新开发的 pbivis 项目中什么都没有显示,除非我转到我的报告的另一个选项卡,然后回到这个具有这个新开发的 pbivis 的选项卡(这是我一开始认为它不起作用的原因,对不起)。

看截图

在此处输入图像描述

我还注意到,如果我最大化这个项目(pbivis),那么图表就会消失(即什么也不显示)。

我想我需要一种代码来刷新可能出现在 df <- data.frame(Values) 之前的视觉效果,可能类似于 IE 中的 F5。

也试过这个,但没有奏效:

if (file.exists("out.html")) 
   #Delete file if it exists
   file.remove("out.html")

标签: rgoogle-visualizationpowerbigooglevis

解决方案


正如 user3867743 所建议的,这个问题与

cat(g$html$chart, file="out.html")

将其替换为

print(g, file="out.html")

它已经开始正常工作了。


推荐阅读