Note: The JavaScript method is best for simple datasets already present in the browser's memory. Which Method Should You Choose?
library(plotly) library(crosstalk) library(DT) # Wrap your data in a SharedData object sd <- SharedData$new(mtcars) # Create a layout with a plot and a table bscols( plot_ly(sd, x = ~wt, y = ~mpg, type = "scatter", mode = "markers"), datatable(sd, extensions = 'Buttons', options = list( dom = 'Bfrtip', buttons = c('csv', 'excel') )) ) Use code with caution. r plotly download data
library(plotly) library(htmlwidgets) plot_ly(mtcars, x = ~hp, y = ~qsec) %>% config( modeBarButtonsToAdd = list( list( name = "Download Data", icon = list(width = 500, ascent = 500, descent = 0, path = "M448 344v64c0 22.1-17.9 40-40 40H40c-22.1 0-40-17.9-40-40v-64c0-22.1 17.9-40 40-40h88c8.8 0 16 7.2 16 16s-7.2 16-16 16H40v64h368v-64h-88c-8.8 0-16-7.2-16-16s7.2-16 16-16h88c22.1 0 40 17.9 40 40z..."), # Simplified SVG path click = htmlwidgets::JS("function(gd) { var text = ''; var data = gd.data[0].x.map((x, i) => x + ',' + gd.data[0].y[i]).join('\\n'); var blob = new Blob([data], {type: 'text/csv'}); var a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'data.csv'; a.click(); }") ) ) ) Use code with caution. Note: The JavaScript method is best for simple