Black Lives Matter. Please consider donating to Black Girls Code today.

How to export React-Plotly as an image, and change its background?

I’m working with React-Plotly, and I’m trying to figure out how to export toImage, similar to the static export. I noticed in the React-Plotly docs that a onBeforeExport and onAfterExport event are emitted, but I can’t seem to figure out how to export the view of a Plotly component. If using download image in the modebar is the only way to do this, there aren’t any event handlers for downloading, like onBeforeDownload or onAfterDownload.

In addition to exporting the plot as a png, I’m trying to also change the background color during the export process. The plot is currently transparent, but I’m trying to give it a white background in the exported version.

Any help would be greatly appreciated!