Writing interactive code
In this section, we'll highlight some important things to know when writing interactive code in Dnotebook.
Loading external packages
Importing external packages into your notebook is very important when writing JavaScript, and as such, Dnotebook has an inbuilt function called load_package
for doing this.
The load_package
method helps you to easily add external packages/libraries to your notebook via their CDN links. For instance, to load Tensorflow.js
and Plotly.js
, you can pass their CDN links to the load_package
function, as shown in the following code:
load_package(["https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.4.0/dist/tf.min.js","https://cdn.plot.ly/plotly-latest.min.js"])
This loads the packages and adds them to the notebook state so they can be accessed from any cell. In the following section, we use the Plotly
library we just imported.
Add the following code to a new cell in your notebook:
trace1 = {...