@@ -707,6 +707,46 @@ runExample <- function(example=NA,
707
707
}
708
708
}
709
709
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
+
710
750
# ' Run a Shiny application from https://gist.github.com
711
751
# '
712
752
# ' Download and launch a Shiny application that is hosted on GitHub as a gist.
@@ -720,16 +760,12 @@ runExample <- function(example=NA,
720
760
# ' launched automatically after the app is started. Defaults to true in
721
761
# ' interactive sessions only.
722
762
# '
723
- # ' @note Requires the \code{RCurl} package.
724
- # '
725
763
# ' @export
726
764
runGist <- function (gist ,
727
765
port = 8100L ,
728
766
launch.browser = getOption(' shiny.launch.browser' ,
729
767
interactive())) {
730
- if (! require(RCurl , quietly = TRUE ))
731
- stop(" Please install package 'RCurl' before attempting to use runGist" )
732
-
768
+
733
769
gistUrl <- if (is.numeric(gist ) || grepl(' ^[0-9a-f]+$' , gist )) {
734
770
sprintf(' https://gist.github.com/gists/%s/download' , gist )
735
771
} else if (grepl(' ^https://gist.github.com/([0-9a-f]+)$' , gist )) {
@@ -742,18 +778,15 @@ runGist <- function(gist,
742
778
stop(' Unrecognized gist identifier format' )
743
779
}
744
780
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 ))
750
784
751
785
dirname <- untar(filePath , list = TRUE )[1 ]
752
786
untar(filePath , exdir = dirname(filePath ))
753
787
754
- # TODO: Remove tarball and expanded directory when finished
788
+ appdir <- file.path(dirname(filePath ), dirname )
789
+ on.exit(unlink(appdir , recursive = TRUE ))
755
790
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 )
759
792
}
0 commit comments