score:0
Change
pbiviz new pbiDensity -t html
for
pbiviz new pbiDensity -t rhtml
score:3
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")
score:9
For newer versions of PowerBI, it's also possible to produce Plotly
charts using R
and ggplot
as custom PowerBI visualizations
. With the approach described below, you can produce a density plot from a PowerBI table like this:
Resources:
My suggested solution uses nodejs
that can be found here. That, as well as the main parts of my suggestion builds on this excellent blogpost that only has some few shortcomings when it comes to the details about using and updating custom PowerBI Visualizations
. I could just refer to that link and point out the things I did differently, but for the sake of clarity and completeness, I've done the whole thing from scratch.
Part 1 - Download and install node.js
1.1: Link: https://nodejs.org/en/
1.2: Restart your computer, launch a command prompt, and run this:
npm install -g powerbi-visuals-tools
1.3: Check that your installation is successful by running the following in your command prompt:
Input:
pbiviz
Output:
Part 2: Make a PowerBI custom visual
2.1: Create a folder to contain your custom visualizations.
I'm using a command prompt to do this
# from the C:\ directory:
md pbiCustomR
cd pbiCustomR
In that folder, run the following command:
pbiviz new pbiDensity -t html
This will create a new visual and install some required packages. You can change pbiDensity
to whatever your want.
2.2: Navigate to the folder C:\pbiCustomR\pbiDensity
and take a closer look at the contents.
There's a lot of stuff there, but we are only going to focus on the file script.R
as well as the file pbiDensity.pbiviz
(located in the subfolder dist
). script.R
is a template that sets up your R script. We're going to edit that later. pbiDensity.pbiviz
is a PowerBI custom visualization that you'll import in Power BI later too.
2.3: Open the file C:pbiqp\script.R
to see this (I highly recommend RStudio):
source('./r_files/flatten_HTML.r')
############### Library Declarations ###############
libraryRequireInstall("ggplot2");
libraryRequireInstall("plotly")
####################################################
################### Actual code ####################
g = qplot(`Petal.Length`, data = iris,fill = `Species`, main = Sys.time());
####################################################
############# Create and save widget ###############
p = ggplotly(g);
internalSaveWidget(p, 'out.html');
####################################################
The snippet above uses a dataset from the Iris
dataset, but we're going to make use of data available in a PowerBI file by adding this line:
df <- data.frame(X = Values$Data)
That line builds a dataframe from an existing column i PowerBI file that we're going to to name Data
. But first, go ahead and change the complete snippet above to:
source('./r_files/flatten_HTML.r')
############### Library Declarations ###############
libraryRequireInstall("ggplot2");
libraryRequireInstall("plotly")
####################################################
################### Actual code ####################
df <- data.frame(X = Values$Data)
# Build basic ggplot
g <- ggplot(df, aes(x = X))
# Add density plot
g = g + geom_density(colour = 'blue')
############# Create and save widget ###############
p = ggplotly(g);
internalSaveWidget(p, 'out.html');
####################################################
2.4: Finish your custom visualization.
In the folder C:\pbiCustomR\pbiDensity
, run the following command using the command prompt:
pbiviz package
This will trigger this output:
And that's it when it comes to the more advanced stuff. The rest is easy!
Part 3 - Make some random data in PowerBI using R
3.1 Under the Home
tab, click Edit Queries
to open the Power Query Editor
.
3.2 Click Enter Data
, and only click OK
.
3.3 Select Transform > Run R Script
and insert the following snippet:
set.seed(123)
output <- data.frame(rnorm(100, mean=100, sd=10))
This will produce a new step under Query Settings
called "output"
, as well as a table with random numbers with not the best column name in the world.
3.4 Change the name of the step under Applied Steps
to tblRandom
, and the name of the column to SampleData
so you'll end up with this:
3.5 Select Home > Close&Apply
to get back to PowerBI Desktop.
**Part 4 - Import and use your custom visualization
4.1 Under Visualizations
, click the icon with the three dots and select Import from file
:
4.1 Navigate to C:\pbiCustomR\pbiDensity\dist
, select pbiDensity.pbiviz
, click OK
and a new icon should appear under Visualizations
:
And this is important
: In order for your visualization to work, the name of your column has to match the reference in your R script. And in our case, they don't (just to make a point out of it). So change the name column SampleData
to Data
.
4.2 Click your new icon to insert a visualization placeholder, and drag your Data
column to it:
And there you go:
Now you have the full flexibility of the plotly
toolbar at your disposal:
Part 5 - Edit R script, update and reimport custom visualization
5.1 Edit your script in RStudio and save it without changing the filename
5.2 Navigate to your custom folder and run pbiviz package
5.3 Delete your existing custom visual in PowerBI and import it again
Source: stackoverflow.com
Related Query
- Is it possible to use R Plotly library in R Script Visual of Power BI?
- Possible to use xAxis with type "datetime" and yAxis with categories?
- Is it possible to use jQuery in wicked_pdf to render charts?
- Using PhantomJS to create HighCharts grahps server side for use in PDF creation (PHP) - results in exit code 11 from PHPs exec();
- How to use HighCharts dart library in Flutter app?
- c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page"
- Do I need to download a specific js library to use highcharts-ng directive or is it already embedded in highcharts.js
- Use of DotNet HighCharts dll to make charts in code behind
- how to use highcharts tooltip formatter in python code
- Possible to use Highcharts Scatter Plot with categories?
- Possible to force Highcarts to use the circle symbol for all the series in a line graph?
- Simple, Open source PHP wrapper for Highcharts library
- Is it possible use size (z) argument with RHighcharter and a categorical Y-axis?
- Is it possible to use null datapoints with a datetime x-axis?
- Strange character in the Highstock source code
- What's the code in Highcharts such that the bars (columns) in the same group use the same color?
- Is it possible to use multi path symbols in highcharts?
- Is it possible to use custom fonts in Highcharts?
- x-axis, y-axis lines does not appear, when I include 3D chart library of HighChart in my code
- How to use specific version of external library in jsfiddle?
- Is it possible to use boost-canvas without enable WebGL in highcharts (current version 9.0.1)?
- How to use highchart boost library with D3?
- Is it possible to customize the features of stack parameter in highchart.js library
- Use HTML class as Highcharts table data source
- Use Node.js as data source for highcharts
- Is it possible to use data grouping in Highcharts without Highstocks?
- Use django variable (array of elements from sqlite3 database) inside javascript embedded code
- Is it possible to use the offline export in stockchart?
- Is it possible with Chart js or which chart Library can provide this type of chart?
- how can I use rangeselector and navigation in highcharts in the given code
More Query from same tag
- how to display the date at X axis and other column at y axis in highcharts
- jQuery HighCharts colour by column
- Daily compound aggregation of Django's ``User`` models' ``date_joined`` field (for graphing with Highcharts)
- print multiple highcharts chart
- How to Integrate Flot with AngularJS?
- Can't change date format on Highcharts
- How to have a negative colour on an area chart as a gradient?
- High chart - Column Range Chart with Time range. How to get tooltip as Start and End time
- highchart axis label can't set at beginning of the label?
- X-axis category name from string in series list
- highcharts lang.resetZoom doesn't appear to work
- Formatting dataLabels in Highcharts
- HighCharts error #18: Requested Axis Does not exist
- highcharts not loading in tabs
- Removing hh:mm:ss from PHP's strtotime function
- Highcharts, Safari 6 and the curious case of the vertically aligned bar chart
- Formatting JSON Data with ColdFusion for HighCharts
- highcharts How to automatically extended columns
- Highcharts Drilldown charts CodeIgniter
- Error while adding and removing plotLine on highcharts
- Highcharts / highstock how to change title of chart in IE?
- Highcharts Series - want to show/hide all EXCEPT selected series (reversal of default logic)
- Print Highstock with custom html
- highcharts x axis date variable range
- Highcharts not display for iOS and Safari
- Highcharts bar chart x-axis inconsistent behaviour
- Highchart - give to series-marker other zIndex then to the series-lines
- How to set the highcharts interactive with select option
- xAxis Categories Highcharts
- HighCharts Orgcharts make scroll able container