diff --git a/R/plotly.R b/R/plotly.R index d87a0cc24c..5d27d359c5 100644 --- a/R/plotly.R +++ b/R/plotly.R @@ -57,7 +57,7 @@ #' } -plotly <- function(username=NULL, key=NULL, base.url="https://plot.ly") { +plotly <- function(username=NULL, key=NULL, base.url=NULL) { if (is.null(username)) { username <- get_credentials_file(c("username", "api_key"))$username @@ -72,6 +72,13 @@ To get started, save your plotly username and API key by calling:\n > set_credentials_file(UserName, ApiKey)\n For more help, see https://plot.ly/R or contact .") } + # Plotly server + if (is.null(base.url)) { + base.url <- get_config_file("plotly_domain")$plotly_domain + } + if (is.null(base.url) || base.url == "") { + base.url <- "https://plot.ly" + } # public attributes/methods that the user has access to pub <- list(username=username, key=key, filename="from api", fileopt=NULL, diff --git a/R/tools.R b/R/tools.R index f866cd9ae0..5a97fe2564 100644 --- a/R/tools.R +++ b/R/tools.R @@ -8,16 +8,15 @@ CONFIG_FILE <- file.path(PLOTLY_DIR, ".config") # THEMES_FILE <- file.path(PLOTLY_DIR, ".themes") -#' Create Plotly credentials file if nonexistent -ensure_local_plotly_files_exist <- function() { - if (!file.exists(PLOTLY_DIR)) { - dir.create(PLOTLY_DIR) - } - for (filename in c(CREDENTIALS_FILE)) { # , PLOT_OPTIONS_FILE, THEMES_FILE - if (!file.exists(filename)) { - file.create(filename) - } +#' Create file if nonexistent +#' @param abspath Character vector of file path +#' @return NULL +ensure_file_exist <- function(abspath) { + if (!file.exists(abspath)) { + dir.create(dirname(abspath), showWarnings=FALSE, recursive=TRUE) + file.create(abspath) } + invisible() } @@ -31,7 +30,7 @@ ensure_local_plotly_files_exist <- function() { #' get_credentials_file(c("username", "api_key")) #' } get_credentials_file <- function(args=c()) { - ensure_local_plotly_files_exist() + ensure_file_exist(CREDENTIALS_FILE) if (file.info(CREDENTIALS_FILE)$size) { credentials_data <- fromJSON(CREDENTIALS_FILE) if (!is.null(args)) { @@ -99,9 +98,7 @@ set_credentials_file <- function(username="", api_key="", #' get_config_file(c("plotly_domain", "plotly_streaming_domain")) #' } get_config_file <- function(args=c()) { - if (!file.exists(CONFIG_FILE)) { - file.create(CONFIG_FILE) - } + ensure_file_exist(CONFIG_FILE) if (file.info(CONFIG_FILE)$size) { config_data <- fromJSON(CONFIG_FILE) if (!is.null(args)) { diff --git a/man/lty2dash.Rd b/man/lty2dash.Rd index 8e3cf9ae13..cf9af4fdae 100644 --- a/man/lty2dash.Rd +++ b/man/lty2dash.Rd @@ -3,7 +3,7 @@ \name{lty2dash} \alias{lty2dash} \title{Convert R lty line type codes to plotly "dash" codes.} -\format{\preformatted{ Named chr [1:25] "solid" "dash" "dot" "dashdot" "longdash" "longdashdot" ... +\format{\preformatted{ Named chr [1:25] "solid" "dash" "dot" "dashdot" "longdash" "longdashdot" "solid" ... - attr(*, "names")= chr [1:25] "1" "2" "3" "4" ... }} \usage{ diff --git a/man/plotly.Rd b/man/plotly.Rd index 1c7d49da0e..20a736da52 100644 --- a/man/plotly.Rd +++ b/man/plotly.Rd @@ -3,7 +3,7 @@ \alias{plotly} \title{Main interface to plotly} \usage{ -plotly(username = NULL, key = NULL, base.url = "https://plot.ly") +plotly(username = NULL, key = NULL, base.url = NULL) } \arguments{ \item{username}{plotly username}