🥣 Mixing Python & R in a single report

Hi! I hope everyone is well here :)

I wanted to share this little protocol I did with my friend (& colleague) @TH. It's a little reporting protocol generating 3 simple charts, BUT in 3 different ways! AND in simple but reusable components. What's not to like!

It's not about the chart here, it's about having a quick starting point, for you to learn how to reuse some snippets of R or Python code, and use them both in a single protocol.

The protocol looks like this:

The magic behind:

  1. Each script generates one chart
    • R Scripts generate an image
    • Python scripts generate a base64 string of an image & then PilotScript ConvertFromBase64() converts it into an image
  2. Image from Data component creates a Reporting element from the image
  3. Any Report Viewer will do :)
  4. Bathe in glory


They are also componentized, so you can learn how to add a few parameters to your component, so that your friends don't have to go in your R or Python code.

Notable Differences


Histogram (Jupyter)

Line Chart (Python)R
Script componentPython Jupyter Notebook (on Server)Python (on Server)R Custom Script
Before the component-Merge All Data-
Color parameter mapping

import ppdataloader
plp_df, plp_params, plp_globals = ppdataloader.loadPipelinePilotData()

color = plp_globals.get('Color')

import pilotpython

context= pilotpython.Context(ctxt)

props= context.getComponentParameters();

color= props.get("Color").getValue().getString()

\\\$(Color)
Output PortPass PortPass Port

Fail Port

PilotScript after the ComponentConvertFromBase64(Histogram)ConvertFromBase64(Plot)-


And yes it works, see the output:

I told you, it was not about the chart 😉


Here is the protocol together with the 3 components:

​​​​​​​

Enjoy