Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Plotly.newplot not working with HTML

Plotly.newplot is working fine in my R Studio Viewer, but when I save to HTML it does not work.
I have a heatmap plot and when you click on a cell the columns in the correlation matrix are plotted below the heatmap.

The code I’m using is below.
It seems the problem is when I save the HTML file.

corr <- plot_ly(colors=“RdBu”) %>%
z=~round(cor(rdata), 3)
) %>%
function(el) {
Plotly.d3.json(‘rdata.json’, function(rdata) {
el.on(‘plotly_click’, function(d) {
var x = d.points[0].x;
var y = d.points[0].y;
var trace = {
x: rdata,
y: rdata[y],
mode: ‘markers’
Plotly.newPlot(‘filtered-plot’, [trace]);

withr::with_path(tempdir(), {
jsonlite::write_json(as.list(rdata), “rdata.json”)
html <- tagList(corr, tags$div(id = ‘filtered-plot’))
save_html(html, “index.html”)
if (interactive()) servr::httd()

Any suggestions on what I’m doing wrong ?

Many Thanks.