JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://cdn.plot.ly/plotly-2.16.2.min.js"></script>
<div id="myDiv"></div>

JavaScript

var data = [{x: [1, 2, 3, 4], y: [10, 15, 13, 17], mode: 'markers'}];
Plotly.newPlot('myDiv', data, {}, {modeBarButtons: [["drawline"]]});
var myDiv = document.getElementById('myDiv');
myDiv.on('plotly_relayout', (event) => {
    if ('shapes' in event) {
        if (event["shapes"].length > 1) {
            console.log(event["shapes"].slice(-1));
            Plotly.relayout(myDiv, { shapes: [] });
        }
    }
});