Testtest11
Testtest11

Reputation: 367

Plotly in R Power BI

How I can create interactive R plots in Power BI (for example 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)

Upvotes: 2

Views: 2930

Answers (3)

Jared Marx
Jared Marx

Reputation: 63

According to this question in Power BI's Community forums

Plotly lib is supported as part of HTML support for R powered Custom Visuals only, not R Visuals in general currently.

Plotly can only be used if it produces an IMAGE\PNG for R visuals in PBI. Not HTML.

For Custom Visuals we have an upcoming feature which will also enable R-based custom visuals to render as htmls.

Hope this helps.

Upvotes: 4

Nguyen Quang
Nguyen Quang

Reputation: 1

PowerBI only supports charts rendered as PNG while plotly format is in HTML. You can try to save the chart as PNG then print it in the R console inside PowerBI. 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. You will be able to generate API key. Copy and paste your username and API key using this code.

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.

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. To create an interactive plot in PowerBI, you have to create a custom visual. Follow an R custom visual example here or radacad example here.

Upvotes: 0

Lifu Huang
Lifu Huang

Reputation: 12867

The reason is that right now Power BI only supports render charts created by R visualization component as 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.

If you want to create interactive visualizations using plotly. The only way you can do is to create a custom Power BI visualization and import it to your report. See this post for a good introduction.

Upvotes: 2

Related Questions