Create Custom Visual with R and JSON- Part 4

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

In the last Post, I have explained some parts of creating Custom visual such as how to create an icon, name of visual, and the how-to allocates fields to a custom visual.

There are some other settings that need to be set up beforehand as well.

the number of data fields you able to pass to each field is matter.

what is mean? in Power BI, sometimes we able to pass as many as data fields to a visual field. But in the most of the cases, we just need to pass one column. Look at the below image:

so how could I manage my visual to accept only one or many values?

back to the folder that we have from creating custom visual, we need to change the “capabilities.json” and add other elements. name data view mapping object to specify the maximum number of variable that each field able to accept. As you can see in the below image, each variable just able to accept one variable no more.

 

Now, imagine, we want to add some more settings., For me, I want to provide a possibility, that the user able to change the chart type such as”Bar chart”, “Scatter chart” or “Boxplot”.

I need to change some setting. for now, I do not have any setting in my visual.

to add a more Visual setting, we need to change capabilities.json file, script.r, and settings.ts file in “src” folder.

First, we need to change the code in capabilities.  under the object node, we need to create another node “settings_ChartType_params”. as you can see in the blow image, I create an enumeration for chart types.

Next, we need to add some code to the script.r file

I add some codes to read data from setting in my script.r file as below

Then, I need to change the code in the setting.ts file.

Now you need to customize your R codes regarding the chart type. In R code also we need to change the code to provide some if then else setting as below.

 

Finally, we need to compile the package again as always to see the result. in command prompt just write “pbiviz package”.

As you see in the above image, in Visual, I have a setting called chart, and under it, I have a field that let me change the chart type.

Still many things that can be covered in this subject, Creating custom visual can be so easy or can be so complicated by adding different settings, like how to pass the error message, and some other information, hope so in other posts I am able to cover them all. Also, check the https://github.com/Microsoft/PowerBI-visuals/blob/master/RVisualTutorial/TutorialFunnelPlot/tutorialScript.txt by Microsoft team data scientist.

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail
rssyoutuberssyoutube
Leila Etaati
Dr. Leila Etaati is Principal Data Scientist, BI Consultant, and Speaker. She has over 10 years’ experience working with databases and software systems. She was involved in many large-scale projects for big sized companies. Leila has PhD of Information System department, University of Auckland, MS and BS in computer science. Leila is Microsoft Data Platform MVP.

Leave a Reply

Your email address will not be published. Required fields are marked *