简体   繁体   English

在 R Power BI 中绘图

[英]Plotly in R Power BI

How I can create interactive R plots in Power BI (for example Plotly)?如何在 Power BI 中创建交互式 R 图(例如 Plotly)? Below code doesn't return any error, but also doesn't show chart:下面的代码不返回任何错误,但也不显示图表:

library(plotly)
library(ggplot2)

z = ggplot(data = dataset) + geom_point(mapping = aes(x = Console, y = Search))
ggplotly(z)

Data source:数据来源:

source <- "https://cdn.rawgit.com/BlueGranite/Microsoft-R-Resources/master/power-bi/gameconsole.csv"  
game.console <- read.csv(source, header = TRUE)

Accoring to this question in Power BI's Community forums 根据 Power BI 社区论坛中的这个问题

Plotly lib is supported as part of HTML support for R powered Custom Visuals only, not R Visuals in general currently. Plotly lib 仅作为对 R 驱动的自定义视觉对象的 HTML 支持的一部分受支持,目前一般不支持 R 视觉对象。

Plotly can only be used if it produces an IMAGE\\PNG for R visuals in PBI.只有在 PBI 中为 R 视觉效果生成 IMAGE\\PNG 时,才能使用 Plotly。 Not HTML.不是 HTML。

For Custom Visuals we have an upcoming feature which will also enable R-based custom visuals to render as htmls.对于自定义视觉效果,我们即将推出一项功能,该功能还将使基于 R 的自定义视觉效果能够呈现为 html。

Hope this helps.希望这会有所帮助。

The reason is that right now Power BI only supports render charts created by R visualization component as PNG.原因是目前 Power BI 仅支持由 R 可视化组件创建的渲染图表为 PNG。

Try the following:请尝试以下操作:

p <- plot_ly(x = dataset$period, y = dataset$mean, name = "spline", line = list(shape = "spline"))
plotly_IMAGE(p, format = "png", out_file = "out.png")

But the problem with this is that, though rendered by plotly, the visualizations will not be interactive since its just a PNG image.但问题在于,虽然由 plotly 呈现,但可视化不会是交互式的,因为它只是一个 PNG 图像。

If you want to create interactive visualizations using plotly.如果您想使用 plotly 创建交互式可视化。 The only way you can do is to create a custom Power BI visualization and import it to your report.您可以做的唯一方法是创建自定义 Power BI 可视化并将其导入到您的报表中。 See this post for a good introduction.请参阅这篇文章以获得很好的介绍。

PowerBI only supports charts rendered as PNG while plotly format is in HTML. PowerBI 仅支持呈现为 PNG 的图表,而 plotly 格式为 HTML。 You can try to save the chart as PNG then print it in the R console inside PowerBI.您可以尝试将图表保存为 PNG,然后在 PowerBI 内的 R 控制台中打印它。 You first have to register a plotly account here .你首先必须在这里注册一个阴谋帐户。

After registration, on the top right corner arrow next to your account name and click on Settings -> API keys.注册后,在您的帐户名称旁边的右上角箭头上,然后单击设置 -> API 密钥。 You will be able to generate API key.您将能够生成 API 密钥。 Copy and paste your username and API key using this code.使用此代码复制并粘贴您的用户名和 API 密钥。

Sys.setenv("plotly_username"="....")
Sys.setenv("plotly_api_key"=".....")

Then add this code in to turn the plot into png format and print it out.然后添加此代码将绘图转换为 png 格式并打印出来。

fig <- plot_ly(x = dataset$Console, y = dataset$Search)
Png <- plotly_IMAGE(fig, out_file = "plotly-test-image.png")
print(Png)

As mentioned in another answer, this plot won't be interactive as plot in PowerBI.正如另一个答案中提到的,这个图不会像 PowerBI 中的图那样具有交互性。 To create an interactive plot in PowerBI, you have to create a custom visual.要在 PowerBI 中创建交互式绘图,您必须创建自定义视觉对象。 Follow an R custom visual example here or radacad examplehere .遵循的R定制视觉例如这里或radacad例子在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM