R visuals not producing graphs in power bi - r

I am trying to create some R visuals in Power BI using the googleVis and/or plotly libraries, but no matter what I do, I can’t get Power BI to display anything. It always just says “No image was created. The R code didn’t result in creation of any visuals. Make sure your R script results in a plot to the R default device.” The issue occurs with plotly and googleVis libraries, so I think it may have something to do with the fact that they’re both browser-based outputs. Per Microsoft, plotly is supported in Power BI. I was hoping someone could tell me why I can’t get any of these example scripts to work in Power BI.
Example code which works in R, but not pbi.
plotly
library(plotly)
p <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
p
googleVis
df=data.frame(country=c("US", "GB", "BR"),
val1=c(10,13,14),
val2=c(23,12,32))
Line <- gvisLineChart(df)
plot(Line)

Now, we can create RHTML custom visual in power BI
1) we can use Ploty - to use it you have load you "midwest" data in power BI table
2) then drag it to R script so it will available to R Script .
3) then run R script , it will work

You can render charts created by plotly as PNG:
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 it's just a PNG image.
If you want to create interactive visualizations using plotly. The only way you can do so far is to create a custom Power BI visualization and import it to your report. See this post for a good introduction.

Related

plotly visualization not working in Pyspark kernel on EMR Jupyterhub Notebook

I'm trying to plot graphs using plotly on EMR Jupyterhub Notebook however the graphs are not being rendered in Pyspark kernel. (Note: Python kernel renders the graph just fine)
Sample code I am trying:
data_canada = px.data.gapminder().query("country == 'Canada'")
fig = px.bar(data_canada, x='year', y='pop')
fig.show()
I am able to plot a graph with %%display sparkmagic however I am not able to figure out if we can get plotly working with %%display sparkmagic -
import random
data = [('Person:%s' % i, i, random.randint(1, 5)) for i in range(1, 50)]
columns = ['Name', 'Age', 'Random']
spark_df = spark.createDataFrame(data, columns)
%%display
spark_df
Has anyone tried this successfully? Please advise.
This is the limitation of sparkmagic. You would have to resort to %%local magic. From sparkmagic docs.
Since all code is run on a remote driver through Livy, all structured data must
be serialized to JSON and parsed by the Sparkmagic library so that it can be
manipulated and visualized on the client side. In practice this means that you
must use Python for client-side data manipulation in %%local mode.

google colab with R no rendering plotly figures

Im trying to use the plotly library on google colab using R, i created a new colaboratory notebook with R kernel , tried this simple code from plotly's documentation and result is white cell (seems size of histogram but its not rendering) anyone did experience this issue?
p <- plot_ly(x = ~rnorm(50), type = "histogram")
p

Problem of qicharts2 p chart in Power Bi: no line shown, only dots

This strange issue has been bothered me over a month... I used qicharts2 to plot a p chart in Power Bi. The function works well and showing the correct p chart in R environment. But once loading the code in Power Bi, facing a strage issue that no line shown up, only the dots.
Power Bi Version: 2.73.5586.802 64-bit (September 2019)
R version 3.6.1 (2019-07-05)
The sample data look like:
The code is quite straight forward:
library(qicharts2)
qic(date, error, total,
data = data1,
chart = 'p',
y.percent = TRUE,
title = 'Process Control (P chart)',
ylab = NULL,
xlab = NULL,
show.labels = TRUE
)
No line shown in Power Bi chart, but works fine in R...
By the way, is there any way to format the chart using ggplot2? I searched the site, "qic$data1" won't work due to "not subsettable" issue. Any other alternatives?

Google Slides, R, d3: Insert Interactive Visualizations

I have created an interactive visualization using R and D3 and would like to insert it into a presentation while maintaining its interactivity. Is this possible?
Minimum working example (MWE:
library(networkD3)
# https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata//flare.json
URL <- paste0(
"https://cdn.rawgit.com/christophergandrud/networkD3/",
"master/JSONdata//flare.json")
Flare <- jsonlite::fromJSON(URL, simplifyDataFrame = FALSE)
diagonalNetwork(List = Flare, fontSize = 10, opacity = 0.9)
Presently, I am trying to insert the visualization into a Google Slides presentation but I am open to other slide presentation solutions (e.g. LaTeX/Beamer, PowerPoint, etc.) as long as it achieves my goals. It is preferable to avoid having to mess around with JavaScript directly, hence why I am using the networkD3 package for R.
Aside: a problem with the Beamer route is that the themes are quite ugly and I have yet to see a pretty Beamer presentation.

Export the graph generated by rCharts in shiny application

I want to be able to export the charts generated in my shiny application using rCharts to Image and PDF formats. Is there any provision in the rCharts library for that?
I have earlier used ggvis, It gives an option for resizing the chart in the browser and also an option to download the chart in HTML or PNG format. Anything similar to that?
Edit 1:
I'm using nvd3 and polyCharts as my charting libraries currently.
To download as image or pdf you can use a$exporting(enabled = T), assuming your chart is called a.
library(rCharts)
a <- hPlot(Pulse ~ Height, data = MASS::survey, type = "scatter", group = "Exer")
a$exporting(enabled = T)
a
To follow up on my comment above, I was a bit too quick to respond, as the htmlwidget::saveWidget() function is meant for widgets developed under the htmlwidgets.org framework. However, rCharts has a similar function:
library(rCharts)
a <- nPlot(Pulse ~ Height, data = MASS::survey, type = "scatterChart", group = "Exer")
a$save("demo.html", standalone=TRUE)
Where 'demo.html' is standalone html file. Creating a png is as simple as taking a screenshot. Note that you can also call this function in a shiny app.

Resources