r - 在 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")
解决方案
正如 user3867743 所建议的,这个问题与
cat(g$html$chart, file="out.html")
将其替换为
print(g, file="out.html")
它已经开始正常工作了。
推荐阅读
- python - 按字母顺序对每个字符串中的字母进行排序 Python 函数
- django - Django Rest Framework:修改序列化器以使用字段作为键而不是对象数组返回字典
- python - python TypeError:不支持的操作数类型/:'builtin_function_or_method'和'int'
- typescript - 使用打字稿中的字段之一创建查找类型
- clojure - 根据字符串类名创建记录
- typescript - TypeScript 可以只迭代接口的“自己的”键吗?
- python - 我的暂停显示如何在 Pygame 中正常工作?
- php - 为什么即使类确实存在并且命名空间正确,我也会收到错误 Class not found
- forms - 使用多个按钮时 SwiftUI 表单容器中的意外行为
- html - 使用视频标签嵌入 Html5 时视频放大