Ravindra BagaleCourses & study guides मराठी Track your progress

14. Visuals and Their Formatting

14.21 R and Python Visuals, and Custom Visuals from AppSource

Start with a problem

Shahrukh found a custom visual on AppSource and also wants a Python plot for a data science colleague.

Explain simply

R and Python visuals run a script on a data frame of the fields you add (R/Python must be installed locally). Custom visuals come from AppSource or a file; your organisation may restrict them.

Show the data

Option Needs Note
Python visual Python + pandas/matplotlib installed Script receives dataset
R visual R installed Script receives dataset
AppSource visual Admin allows it Check certification

About this data: This table uses columns: Option, Needs, Note. This table uses columns: City, Bar height. This table uses columns: Wrong result, Reason, Correction. Values shown are the lesson examples already on this page (not a new dataset).

Fictional sample data. Practice file: visuals_orders_apr_may_2026.csv (source: src/practice/).

Demonstrate

  1. File › Options and settings › Options › Python scripting › set the Python home folder.
  2. Insert Python visual › enable script visuals when asked.
  3. Add City and Amount to Values.
  4. In the script editor, below the generated lines, type: dataset.groupby('City')['Amount'].sum().plot(kind='bar') then import matplotlib.pyplot as plt; plt.show().
  5. Click Run script.

Show the result

Your result should look like this (fictional sample):

City Bar height
Kolhapur 450
Nashik 800
Pune 850

Explain what happened

Power BI passes the visual's fields as a pandas DataFrame named dataset (with duplicate rows removed), runs the script, and shows the image it creates.

Explore further

  • Script visuals are images – no cross-filtering out of them.
  • Prefer certified custom visuals for company reports.

Detailed reference for this lesson:

  • R script visual / Python visual (in the Visualizations pane): you write R or Python code that draws a chart (e.g. a violin plot of delivery times). They require R/Python installed locally (File › Options › R scripting / Python scripting), render as images (limited interactivity), and have limits in the Service. Use them only when no built-in visual fits.
  • Custom visuals (AppSource): Visualizations pane › … (Get more visuals) › Get more visuals › search (for example "Box and whisker", "Gantt", "Sankey") › Add. Or Import a visual from a file (.pbiviz). In organisations, prefer certified visuals and follow your admin's policy. Some visuals send data outside or need a licence.

Ravindra Bagale's Tip

Friends, many students add custom visuals from unknown publishers without checking them, and some organisations block them in the Service. Prefer certified visuals from AppSource, check your organisation's policy, and remember that R and Python visuals need supported runtimes in the Service. Don't worry – after doing it two or three times, it becomes a habit.

Fix common mistakes

Wrong result Reason Correction
Error: Python not found Python home not set Set it in Options › Python scripting
Totals smaller than expected Duplicate rows removed in dataset Add Order ID to keep rows unique
Visual blocked in the Service Tenant settings Ask the admin; use a native visual

Practise independently

Practice task

Without running Python, predict the bar for Pune if Order ID is not added and two Pune rows had identical City and Amount.

Hints
  • Power BI removes duplicate rows before passing dataset.
Solution

Identical rows would be counted once, so the total would be too small. Adding Order ID keeps every row. (In this file Pune rows have different amounts, so Pune shows ₹850.)

Think like a professional

Use script visuals for special analysis, not core KPIs; they are harder to maintain and to secure. Interviewers like hearing that you know the deduplication trap.

Ravi Sir's Cards for this lesson

मराठी cards