I added a button to download image by removing from the legend the data that was not selected.
It works great but I wish I could go back to the original display (and see the deselected data in the legend)…
I see two options:
- prevent showing changes when downloading the image ;
- add a button to reset the chart…
Can you help me ?
Here a reproducible example :
plot_ly(data = mtcars, x = ~ mpg, y = ~ wt, color = ~ factor(cyl),
type = "scatter", mode = "markers") %>%
config(
modeBarButtonsToAdd = list(
list(
name = "Custom download button",
click = htmlwidgets::JS('function(gd) {
let data = gd.data.map(function (datapoint) {
if (datapoint.visible === "legendonly") {
datapoint.visible = false;
}
return datapoint
})
gd.data = data;
Plotly.downloadImage(
gd, {
format: "png",
width: 900,
height: 500
}
);
}')
)
)
)