How to import Plotly to use in Framework

I’m trying to import plotly from a local file (as both import from node_modules and npm:… failed). Both of the following import the module:

  • import * as Plotly from "./plotly.min.js"
  • const Plotly = import(await FileAttachment("plotly.min.js").url())

But in both cases I can access Plotly only from the browser’s inspector (e. g. Plotly.newPlot("plotId") whereas the same expression fails when included in a source markdown’s JS codeblock:
TypeError: Plotly.newPlot is not a function

What am I missing?

hard to tell, since it depends from what plotly.min.js comes from :slight_smile:

It looks like this incantation works:

```js echo
import Plotly from "npm:plotly.js-dist-min";

```js echo
const div = display(document.createElement("div"));

  {data: [{y: [1, 2, 3]}], layout: {width: 600, height: 400}}
1 Like

works like a charm - thank you!

1 Like