2

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)
Testtest11
  • 367
  • 1
  • 11
  • 26
  • 1
    `plotly` is not available in Power BI. See http://community.powerbi.com/t5/Desktop/Is-it-possible-to-use-R-charts-that-use-the-plotly-library-in/td-p/94895 – arun Jan 08 '17 at 03:40

3 Answers3

3

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.

Jared Marx
  • 53
  • 7
  • Hey Jared, Hi and welcome to Stack Overflow, please dont forget to go through the [welcome tour](https://stackoverflow.com/tour) to know your way around here (and also to earn your first badge) – DarkCygnus Jul 07 '17 at 16:25
2

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.

Lifu Huang
  • 11,930
  • 14
  • 55
  • 77
0

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.