# NOT RUN {
# }
# NOT RUN {
# ------------------------------------------------------------
# api_create() makes it easy to upload ggplot2/plotly objects
# and/or data frames to your plotly account
# ------------------------------------------------------------
# A data frame creates a plotly "grid". Printing one will take you
# to the it's web address so you can start creating!
(m <- api_create(mtcars))
# A plotly/ggplot2 object create a plotly "plot".
p <- plot_ly(mtcars, x = ~factor(vs))
(r <- api_create(p))
# api_create() returns metadata about the remote "file". Here is
# one way you could use that metadata to download a plot for local use:
fileID <- strsplit(r$file$fid, ":")[[1]]
layout(
api_download_plot(fileID[2], fileID[1]),
title = sprintf("Local version of <a href='%s'>this</a> plot", r$file$web_url)
)
------------------------------------------------------------
# The api() function provides a low-level interface for performing
# any action at any endpoint! It always returns a list.
# ------------------------------------------------------------
# list all the endpoints
api()
# search the entire platform!
# see https://api.plot.ly/v2/search
api("search?q=overdose")
api("search?q=plottype:pie trump fake")
# these examples will require a user account
usr <- Sys.getenv("plotly_username", NA)
if (!is.na(usr)) {
# your account info https://api.plot.ly/v2/#users
api(sprintf("users/%s", usr))
# your folders/files https://api.plot.ly/v2/folders#user
api(sprintf("folders/home?user=%s", usr))
}
# Retrieve a specific file https://api.plot.ly/v2/files#retrieve
api("files/cpsievert:14681")
# change the filename https://api.plot.ly/v2/files#update
# (note: this won't work unless you have proper credentials to the relevant account)
api("files/cpsievert:14681", "PATCH", list(filename = "toy file"))
# Copy a file https://api.plot.ly/v2/files#lookup
api("files/cpsievert:14681/copy", "POST")
# Create a folder https://api.plot.ly/v2/folders#create
api("folders", "POST", list(path = "/starts/at/root/and/ends/here"))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab