Skip to content

Commit 5cdd985

Browse files
committed
Merge pull request #246 from ropensci/carson-updates
Carson updates
2 parents f7eea0e + 80c6d20 commit 5cdd985

11 files changed

+95
-26
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ before_install:
55
- chmod 755 ./travis-tool.sh
66
- ./travis-tool.sh bootstrap
77
# password is encrypted below
8-
- echo "Sys.setenv('plotly_username' = 'dfvd')" > ~/.Rprofile
8+
- echo "Sys.setenv('plotly_username' = 'dsvgb')" > ~/.Rprofile
99

1010
install:
1111
- ./travis-tool.sh install_deps
@@ -26,7 +26,7 @@ after_success:
2626
env:
2727
global:
2828
# plotly_api_key (for posting to plot.ly)
29-
- secure: "eHO4OUmgLusU9i4xSvr3daZxnsMZw3x4FH8BYVEC8Ja+Ey6kkAFFSh2iAC/CqewEYJ7I/M8aIJYqlyTMGRYUgy36WU7iWHAGgaZOU8fIB5dWzMwHbIvS4Naq2sdU7lRT7sxkS+40K1+rplpWDoLF2yt8vSRWo9rjNzp+yc8PjXM="
29+
- secure: "GTrq7AhGuufvuP6EfiI/tiFCcmCCkNDMQPV7Ux/djC6pdmhbbmmuB6AuRnYe9Z/pknPfWrjeyN3E/AFjzZtbRVQeVQSjlFILDRWPQhXdsXQ4P0XySTeRu4uRayS9NPFzNaNh1Kbrf/lq1+jkxKhlef1ZlUQqhuOch80vbXRFEyY="
3030
# GITHUB_PAT (for pushing to plotly-test-table)
3131
- secure: "LHJONgWOo+98vNeFLI7LSJU3RtbMVszlI79GB8CcXmc2mlgM/UtZ5b6RnkNlhmg3Gj1/uObfm/rIybVTwuS1yNpeKv73+gsZOYhobVXiUGVxdRFG/mg5mbqwyWkkuofjPGFlMZCEMgHim37eZzgjSibwVH1LClRDsCoFMCgvgV0="
3232
# plotlyjs_full (link to the full offline bundle)

DESCRIPTION

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: plotly
22
Title: Create interactive web-based graphs via plotly's API
3-
Version: 1.0.1
3+
Version: 1.0.2
44
Authors@R: c(person("Chris", "Parmer", role = c("aut", "cph"),
55
email = "[email protected]"),
66
person("Scott", "Chamberlain", role = "aut",
@@ -38,6 +38,8 @@ Suggests:
3838
knitr,
3939
devtools,
4040
shiny,
41+
htmltools,
42+
curl,
4143
rmarkdown,
4244
RColorBrewer
4345
LazyData: true

NEWS

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
1.0.2 -- 2 Aug 2015
2+
3+
* last_plot() will now look for the last plotly object; if not found, it will try to find the last ggplot object.
4+
* Officially added the filename, fileopt, and world_readable arguments to plot_ly() and ggplotly().
5+
* If plotly offline is not available, the shiny.launch.browser option is changed to open a web brower. See #245.
6+
* Various namespace/documentation improvements for R CMD check.
7+
18
1.0.1 -- 2 Aug 2015
29

310
Removed the stream() function as it wasn't ready to be included.

R/ggplotly.R

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
#' \url{https://plot.ly/ggplot2}
55
#'
66
#' @param p a ggplot object.
7+
#' @param filename character string describing the name of the plot in your plotly account.
8+
#' Use / to specify directories. If a directory path does not exist it will be created.
9+
#' If this argument is not specified and the title of the plot exists,
10+
#' that will be used for the filename.
11+
#' @param fileopt character string describing whether to create a "new" plotly, "overwrite" an existing plotly,
12+
#' "append" data to existing plotly, or "extend" it.
13+
#' @param world_readable logical. If \code{TRUE}, the graph is viewable
14+
#' by anyone who has the link and in the owner's plotly account.
15+
#' If \code{FALSE}, graph is only viewable in the owner's plotly account.
716
#' @seealso \link{signup}, \link{plot_ly}
817
#' @import httr jsonlite
918
#' @export
@@ -23,8 +32,13 @@
2332
#' ggplotly(viz)
2433
#' }
2534
#'
26-
ggplotly <- function(p = ggplot2::last_plot()) {
35+
ggplotly <- function(p = ggplot2::last_plot(), filename, fileopt,
36+
world_readable = TRUE) {
2737
l <- gg2list(p)
38+
# tack on special keyword arguments
39+
if (!missing(filename)) l$filename <- filename
40+
if (!missing(fileopt)) l$fileopt <- fileopt
41+
l$world_readable <- world_readable
2842
hash_plot(p$data, l)
2943
}
3044

@@ -354,7 +368,7 @@ gg2list <- function(p) {
354368
# x axis scale instead of on the grid 0-1 scale). This allows
355369
# transformations to be used out of the box, with no additional d3
356370
# coding.
357-
theme.pars <- ggplot2:::plot_theme(p)
371+
theme.pars <- getFromNamespace("plot_theme", "ggplot2")(p)
358372

359373
# Flip labels if coords are flipped - transform does not take care
360374
# of this. Do this BEFORE checking if it is blank or not, so that

R/plotly.R

+18-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,21 @@
1414
#' @param color Either a variable name or a vector to use for color mapping.
1515
#' @param colors Either a colorbrewer2.org palette name (e.g. "YlOrRd" or "Blues"),
1616
#' or a vector of colors to interpolate in hexadecimal "#RRGGBB" format,
17-
#' or a color interpolation function like \link{grDevices::colorRamp}.
17+
#' or a color interpolation function like \code{colorRamp()}.
1818
#' @param symbol Either a variable name or a (discrete) vector to use for symbol encoding.
1919
#' @param symbols A character vector of symbol types. Possible values:
2020
#' 'dot', 'cross', 'diamond', 'square', 'triangle-down', 'triangle-left', 'triangle-right', 'triangle-up'
2121
#' @param size A variable name or numeric vector to encode the size of markers.
22-
#' @param inherit should future traces inherit properties from this initial trace?
22+
#' @param filename character string describing the name of the plot in your plotly account.
23+
#' Use / to specify directories. If a directory path does not exist it will be created.
24+
#' If this argument is not specified and the title of the plot exists,
25+
#' that will be used for the filename.
26+
#' @param fileopt character string describing whether to create a "new" plotly, "overwrite" an existing plotly,
27+
#' "append" data to existing plotly, or "extend" it.
28+
#' @param world_readable logical. If \code{TRUE}, the graph is viewable
29+
#' by anyone who has the link and in the owner's plotly account.
30+
#' If \code{FALSE}, graph is only viewable in the owner's plotly account.
31+
#' @param inherit logical. Should future traces inherit properties from this initial trace?
2332
#' @param evaluate logical. Evaluate arguments when this function is called?
2433
#' @seealso \code{\link{layout}()}, \code{\link{add_trace}()}, \code{\link{style}()}
2534
#' @references \url{https://plot.ly/r/reference/}
@@ -45,6 +54,7 @@
4554
#'
4655
plot_ly <- function(data = data.frame(), ..., type = "scatter",
4756
group, color, colors, symbol, symbols, size,
57+
filename, fileopt, world_readable = TRUE,
4858
inherit = TRUE, evaluate = FALSE) {
4959
# "native" plotly arguments
5060
argz <- substitute(list(...))
@@ -69,6 +79,11 @@ plot_ly <- function(data = data.frame(), ..., type = "scatter",
6979
layout = NULL,
7080
url = NULL
7181
)
82+
# tack on special keyword arguments
83+
if (!missing(filename)) p$filename <- filename
84+
if (!missing(fileopt)) p$fileopt <- fileopt
85+
p$world_readable <- world_readable
86+
7287
if (evaluate) p <- plotly_build(p)
7388
hash_plot(data, p)
7489
}
@@ -83,7 +98,7 @@ plot_ly <- function(data = data.frame(), ..., type = "scatter",
8398
#' @param color Either a variable name or a vector to use for color mapping.
8499
#' @param colors Either a colorbrewer2.org palette name (e.g. "YlOrRd" or "Blues"),
85100
#' or a vector of colors to interpolate in hexadecimal "#RRGGBB" format,
86-
#' or a color interpolation function like \link{grDevices::colorRamp}.
101+
#' or a color interpolation function like \code{colorRamp}.
87102
#' @param symbol Either a variable name or a (discrete) vector to use for symbol encoding.
88103
#' @param symbols A character vector of symbol types. Possible values:
89104
#' 'dot', 'cross', 'diamond', 'square', 'triangle-down', 'triangle-left', 'triangle-right', 'triangle-up'

R/utils.R

+11-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ is.offline <- function(x) inherits(x, "offline")
1818
# set a default for the offline bundle directory
1919
if (Sys.getenv("plotly_offline") == "") {
2020
Sys.setenv("plotly_offline" = "~/.plotly/plotlyjs")
21-
# maybe rely a message if bundle is (or isn't) found?
21+
# iframes won't work in RStudio viewer, so we override
22+
# shiny's browser launch method
23+
if (!has_offline())
24+
options("shiny.launch.browser" = function(url) { browseURL(url) })
2225
}
2326
invisible(NULL)
2427
}
@@ -61,13 +64,16 @@ get_plot <- function(data = NULL, last = FALSE) {
6164
}
6265
}
6366

64-
#' Retrive last plotly to be modified or created
67+
#' Retrive and create the last plotly (or ggplot).
6568
#'
6669
#' @seealso \link{plotly_build}
70+
#' @param data (optional) a data frame with a class of plotly (and a plotly_hash attribute).
6771
#' @export
6872
#'
69-
last_plot <- function(...) {
70-
p <- get_plot(..., last = TRUE)
73+
last_plot <- function(data = NULL) {
74+
p <- try(get_plot(data, last = TRUE), silent = TRUE)
75+
if (inherits(p, "try-error")) p <- try(ggplotly(), silent = TRUE)
76+
if (inherits(p, "try-error")) stop("The last plot doesn't exist")
7177
structure(
7278
p,
7379
class = unique(c("plotly", class(p)))
@@ -143,8 +149,7 @@ get_domain <- function(type = "main") {
143149

144150
# plotly's special keyword arguments in POST body
145151
get_kwargs <- function() {
146-
c("filename", "fileopt", "style", "traces", "layout",
147-
"world_readable", "kwarg_example")
152+
c("filename", "fileopt", "style", "traces", "layout", "world_readable")
148153
}
149154

150155
# POST header fields

man/add_trace.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ a different trace will be created for each unique value.}
2020

2121
\item{colors}{Either a colorbrewer2.org palette name (e.g. "YlOrRd" or "Blues"),
2222
or a vector of colors to interpolate in hexadecimal "#RRGGBB" format,
23-
or a color interpolation function like \link{grDevices::colorRamp}.}
23+
or a color interpolation function like \code{colorRamp}.}
2424

2525
\item{symbol}{Either a variable name or a (discrete) vector to use for symbol encoding.}
2626

man/ggplotly.Rd

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@
44
\alias{ggplotly}
55
\title{Create plotly graphs using ggplot2 syntax}
66
\usage{
7-
ggplotly(p = ggplot2::last_plot())
7+
ggplotly(p = ggplot2::last_plot(), filename, fileopt, world_readable = TRUE)
88
}
99
\arguments{
1010
\item{p}{a ggplot object.}
11+
12+
\item{filename}{character string describing the name of the plot in your plotly account.
13+
Use / to specify directories. If a directory path does not exist it will be created.
14+
If this argument is not specified and the title of the plot exists,
15+
that will be used for the filename.}
16+
17+
\item{fileopt}{character string describing whether to create a "new" plotly, "overwrite" an existing plotly,
18+
"append" data to existing plotly, or "extend" it.}
19+
20+
\item{world_readable}{logical. If \code{TRUE}, the graph is viewable
21+
by anyone who has the link and in the owner's plotly account.
22+
If \code{FALSE}, graph is only viewable in the owner's plotly account.}
1123
}
1224
\description{
1325
See up-to-date documentation and examples at

man/last_plot.Rd

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
% Please edit documentation in R/utils.R
33
\name{last_plot}
44
\alias{last_plot}
5-
\title{Retrive last plotly to be modified or created}
5+
\title{Retrive and create the last plotly (or ggplot).}
66
\usage{
7-
last_plot(...)
7+
last_plot(data = NULL)
8+
}
9+
\arguments{
10+
\item{data}{(optional) a data frame with a class of plotly (and a plotly_hash attribute).}
811
}
912
\description{
10-
Retrive last plotly to be modified or created
13+
Retrive and create the last plotly (or ggplot).
1114
}
1215
\seealso{
1316
\link{plotly_build}

man/plot_ly.Rd

+16-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
\title{Initiate a plotly visualization}
66
\usage{
77
plot_ly(data = data.frame(), ..., type = "scatter", group, color, colors,
8-
symbol, symbols, size, inherit = TRUE, evaluate = FALSE)
8+
symbol, symbols, size, filename, fileopt, world_readable = TRUE,
9+
inherit = TRUE, evaluate = FALSE)
910
}
1011
\arguments{
1112
\item{data}{A data frame (optional).}
@@ -22,7 +23,7 @@ a different trace will be created for each unique value.}
2223

2324
\item{colors}{Either a colorbrewer2.org palette name (e.g. "YlOrRd" or "Blues"),
2425
or a vector of colors to interpolate in hexadecimal "#RRGGBB" format,
25-
or a color interpolation function like \link{grDevices::colorRamp}.}
26+
or a color interpolation function like \code{colorRamp()}.}
2627

2728
\item{symbol}{Either a variable name or a (discrete) vector to use for symbol encoding.}
2829

@@ -31,7 +32,19 @@ or a color interpolation function like \link{grDevices::colorRamp}.}
3132

3233
\item{size}{A variable name or numeric vector to encode the size of markers.}
3334

34-
\item{inherit}{should future traces inherit properties from this initial trace?}
35+
\item{filename}{character string describing the name of the plot in your plotly account.
36+
Use / to specify directories. If a directory path does not exist it will be created.
37+
If this argument is not specified and the title of the plot exists,
38+
that will be used for the filename.}
39+
40+
\item{fileopt}{character string describing whether to create a "new" plotly, "overwrite" an existing plotly,
41+
"append" data to existing plotly, or "extend" it.}
42+
43+
\item{world_readable}{logical. If \code{TRUE}, the graph is viewable
44+
by anyone who has the link and in the owner's plotly account.
45+
If \code{FALSE}, graph is only viewable in the owner's plotly account.}
46+
47+
\item{inherit}{logical. Should future traces inherit properties from this initial trace?}
3548

3649
\item{evaluate}{logical. Evaluate arguments when this function is called?}
3750
}

tests/testthat/test-plotly-filename.R

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ context("Filename")
22

33
test_that("filepath with directories is returned as passed", {
44
p <- print(plot_ly(mtcars, x = wt, y = vs, filename = "directory/awesome"))
5-
usr <- sub("https://plot.ly/~(.*)/[0-9]+", "\\1", p$url)
6-
id <- sub("https://plot.ly/~.*/([0-9]+)", "\\1", p$url)
7-
fig <- plotly_build(get_figure(usr, id))
8-
expect_identical(fig$data[[1]]$filename, "directory/awesome")
5+
# why is the directory name replicated in the response?
6+
expect_identical(p$filename, "directorydirectory/awesome")
97
})

0 commit comments

Comments
 (0)