I have a plotly graph (in my case made in R / rmarkdown), and would like to download the data.
- Option 1 is a download button outside the graph to a data object (e.g CSV, or a table). For example Download output file csv, or this. It works, but not that neat - using custom modebar would be neater.
Options 2 and 3 use a custom modebar button. plotly book - custom modebar button has a nice example with code to make the custom button.
-
Option 2, is a download button (e.g. to csv) as a plotly custom modebar button. Presumably this could be done in javascript (or html) and passed through, similar to example below in option 3? Suggestions for how to do this? There is some discussion on this option at Plotly forum, using Dash(?), but that is well over my pay grade.
-
Option 3 is a button that links to a table (possibly an appendix or other website with a datatable object), where that datatable has a download button. The last part, making a button for datatable that you can click is easy (see here). The javascript code for a website link should look something like this (javascript link to website). The default Plotly button in a plotly modebar does send you to a linked website when you click, but not sure how to replicate that html/javascript from R.
Am I missing something simple in this code?
#devtools::install_github('cpsievert/plotly_book') #for octocat image
library(tidyverse)
library(DT)
library(plotly)
data(octocat_svg_path, package = "plotlyBook")
octocat <- list(
name = "octocat",
icon = list(
path = octocat_svg_path,
transform = 'matrix(1 0 0 1 -2 -2) scale(0.7)'
),
click = htmlwidgets::JS(
"function(gd) {window.location.href = 'http://www.google.com';
}"
)
)
plot_ly() %>%
config(modeBarButtonsToAdd = list(octocat))
from Download data from plotly graph via custom modebar button, coded in R
No comments:
Post a Comment