# Passing plotly script as external library

**URL:** <https://community.postman.com/t/passing-plotly-script-as-external-library/29055>\
**Category:** Help Hub\
**Tags:** template, visualizer\
**Created:** [October 25, 2021, 7:18am UTC](https://community.postman.com/t/passing-plotly-script-as-external-library/29055 "2021-10-25T07:18:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasannaKul](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@prasannaKul](https://community.postman.com/u/prasannaKul)\
**Post date:** [October 25, 2021, 7:18am UTC](https://community.postman.com/t/passing-plotly-script-as-external-library/29055/1 "2021-10-25T07:18:50Z")

</div>

Hi,  
I am trying to set up Visualizer with Plotly library, and facing few issues.  
Firstly I tried to load plotly min js via \<script\> tag, but got into CSP issues, for the unsafe inline script.  
Then I researched and came across the below link, which guides about how we can load extenral/CDN js in POSTMAN test scripts and I tried that for Plotly.

> [@Adding external libraries to postman](https://community.postman.com/t/adding-external-libraries-to-postman/1971/4):
>
> @yoelspotts You’ll first have to check if the library in question has a CDN equivalent that you can use. For instance, if you’d like to use [strman](https://npmjs.org/package/strman), you can head over to it’s CDN link: [https://cdnjs.cloudflare.com/ajax/libs/strman/1.3.1/strman.js](https://cdnjs.cloudflare.com/ajax/libs/strman/1.3.1/strman.js), copy the contents over into the value of an environment variable, say strman\_code. Next, you can include this within your code by adding the following snippet of code as the first statement in every request level pre-request/test script: const strman\_c…

The Plotly script URL is [https://cdn.plot.ly/plotly-latest.min.js](https://cdn.plot.ly/plotly-latest.min.js)

After this, it seems not able to parse the script and failing for syntax error. Below is the error.  
2RgBbPrVy.html: 21 Uncaught SyntaxError: Unexpected token ‘&’

I tried many minor alternatives, but none worked. Please guide further.

My test script code is as below:

var jsonData = JSON.parse(responseBody);

var template = `

\<script\>

```
console.log('creating chart');

const script_plt_fn = (new Function({{script_fn}}))();

const chart_data = {{chart_data}};

const chart_layout = {{chart_layout}};

var div_plot = document.getElementById("myplot");

    Plotly.newPlot(

    div_plot,

    chart_data,

    chart_layout,

    {displaylogo: false}

  );

```

\</script\>

\<div id=“myplot”\>this is my div\</div\>

`;

console.log("this is console log: ",jsonData);

script\_plt = pm.environment.get(‘plotly.min.js’);

//var fn = new Function(script\_plt);

pm.visualizer.set(template, {script\_fn: script\_plt, chart\_data: jsonData.data, chart\_layout:jsonData.layout });
