Skip to content

Commit 790e6f3

Browse files
committed
Remove RCurl dependency
1 parent 16ccc13 commit 790e6f3

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

DESCRIPTION

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Imports:
2222
RJSONIO,
2323
xtable,
2424
digest
25-
Suggests:
26-
RCurl
2725
URL: https://github.com/rstudio/shiny, http://rstudio.github.com/shiny/tutorial
2826
BugReports: https://github.com/rstudio/shiny/issues
2927
Collate:

R/shiny.R

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,46 @@ runExample <- function(example=NA,
707707
}
708708
}
709709

710+
# This is a wrapper for download.file and has the same interface.
711+
# The only difference is that, if the protocol is https, it changes the
712+
# download settings, depending on platform.
713+
download <- function(url, ...) {
714+
# First, check protocol. If https, check platform:
715+
if (grepl('^https://', url)) {
716+
717+
# If Windows, call setInternet2, then use download.file with defaults.
718+
if (.Platform$OS.type == "windows") {
719+
# If we directly use setInternet2, R CMD CHECK gives a Note on Mac/Linux
720+
mySI2 <- eval(parse(text="setInternet2"))
721+
# Store initial settings
722+
internet2_start <- mySI2(NA)
723+
on.exit(mySI2(internet2_start))
724+
725+
# Needed for https
726+
mySI2(TRUE)
727+
download.file(url, ...)
728+
729+
# If non-Windows, check for curl/wget/lynx, then call download.file with
730+
# appropriate method.
731+
} else {
732+
733+
if (system("wget --help > /dev/null") == 0L)
734+
method <- "wget"
735+
else if (system("curl --help > /dev/null") == 0L)
736+
method <- "curl"
737+
else if (system("lynx -help > /dev/null") == 0L)
738+
method <- "lynx"
739+
else
740+
stop("no download method found")
741+
742+
download.file(url, method = method, ...)
743+
}
744+
745+
} else {
746+
download.file(url, ...)
747+
}
748+
}
749+
710750
#' Run a Shiny application from https://gist.github.com
711751
#'
712752
#' Download and launch a Shiny application that is hosted on GitHub as a gist.
@@ -720,16 +760,12 @@ runExample <- function(example=NA,
720760
#' launched automatically after the app is started. Defaults to true in
721761
#' interactive sessions only.
722762
#'
723-
#' @note Requires the \code{RCurl} package.
724-
#'
725763
#' @export
726764
runGist <- function(gist,
727765
port=8100L,
728766
launch.browser=getOption('shiny.launch.browser',
729767
interactive())) {
730-
if (!require(RCurl, quietly=TRUE))
731-
stop("Please install package 'RCurl' before attempting to use runGist")
732-
768+
733769
gistUrl <- if (is.numeric(gist) || grepl('^[0-9a-f]+$', gist)) {
734770
sprintf('https://gist.github.com/gists/%s/download', gist)
735771
} else if(grepl('^https://gist.github.com/([0-9a-f]+)$', gist)) {
@@ -742,18 +778,15 @@ runGist <- function(gist,
742778
stop('Unrecognized gist identifier format')
743779
}
744780
filePath <- tempfile('shinygist', fileext='.tar.gz')
745-
zipdata <- getBinaryURL(gistUrl)
746-
747-
hZipFile <- file(filePath, open='wb', raw=TRUE)
748-
writeBin(zipdata, hZipFile)
749-
close(hZipFile)
781+
if (download(gistUrl, filePath, quiet = TRUE) != 0)
782+
stop("Failed to download URL ", gistUrl)
783+
on.exit(unlink(filePath))
750784

751785
dirname <- untar(filePath, list=TRUE)[1]
752786
untar(filePath, exdir=dirname(filePath))
753787

754-
# TODO: Remove tarball and expanded directory when finished
788+
appdir <- file.path(dirname(filePath), dirname)
789+
on.exit(unlink(appdir, recursive = TRUE))
755790

756-
shiny::runApp(file.path(dirname(filePath), dirname),
757-
port=port,
758-
launch.browser=launch.browser)
791+
shiny::runApp(appdir, port=port, launch.browser=launch.browser)
759792
}

man/runGist.Rd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,4 @@
2323
Download and launch a Shiny application that is hosted on
2424
GitHub as a gist.
2525
}
26-
\note{
27-
Requires the \code{RCurl} package.
28-
}
2926

0 commit comments

Comments
 (0)