26 Control the modebar
By default, the modebar appears in the top right-hand side of a plotly graph on mouse hover, and can lead to poor user-experience on small displays. Fortunately, the modebar can be completely customized via the
config() function. The
config() function can be helpful for a lot of things: language support (Section 30), enabling mathjax (Section 31), suppressing tip notifications (e.g.,
showTips), when to scroll on zoom, etc. However, this topic is all about options related to the modebar. To see a complete list of
config() options, as well as their description, see the config section of the plotly.js
26.1 Remove the entire modebar
displayModeBar option makes it quick and easy to remove the entire modebar.
26.2 Remove the plotly logo
displaylogo option makes it quick and easy to remove the entire modebar.
26.5 Control image downloads
By default, the
toImage modebar button downloads a png file using the current size and state of the graph. With
toImageButtonOptions, one can specify different sizes and filetypes, which is particularly useful for obtaining a static pdf/webp/jpeg/etc image of the plot after components have been directly manipulated, as leveraged in Figure 12.1. Here’s a basic example of configuring the
'toImage' button to download an svg file that’s 200 x 100 pixels:
After downloading the svg file, you can convert it to pdf using the
rsvg_pdf() function from the rsvg package (Ooms 2018).
Ooms, Jeroen. 2018. Rsvg: Render Svg Images into Pdf, Png, Postscript, or Bitmap Arrays. https://CRAN.R-project.org/package=rsvg.