@@ -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
145151get_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
0 commit comments