Skip to content

Commit

Permalink
redoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinFay committed Sep 29, 2021
1 parent 5350fa8 commit 6ea4257
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 88 deletions.
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ importFrom(fs,path_abs)
importFrom(fs,path_expand)
importFrom(fs,path_file)
importFrom(htmltools,htmlDependency)
importFrom(htmltools,save_html)
importFrom(htmltools,tags)
importFrom(pkgload,load_all)
importFrom(pkgload,pkg_name)
importFrom(pkgload,pkg_path)
Expand All @@ -111,6 +109,7 @@ importFrom(rstudioapi,sourceMarkers)
importFrom(shiny,addResourcePath)
importFrom(shiny,getShinyOption)
importFrom(shiny,includeScript)
importFrom(shiny,tags)
importFrom(usethis,proj_set)
importFrom(usethis,use_build_ignore)
importFrom(usethis,use_latest_dependencies)
Expand Down
1 change: 0 additions & 1 deletion R/test_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ expect_shinytaglist <- function(object) {
#' @param ui output of an UI function
#' @param html deprecated
#' @param ... arguments passed to `testthat::expect_snapshot()`
#' @importFrom htmltools save_html
#' @importFrom attempt stop_if_not
expect_html_equal <- function(ui,
html,
Expand Down
152 changes: 71 additions & 81 deletions R/use_favicon.R
Original file line number Diff line number Diff line change
@@ -1,104 +1,100 @@
#' Add a favicon to your shinyapp
#'
#' @param path Path to your favicon file (.ico or .png)
#' @param path Path to your favicon file (.ico or .png)
#' @inheritParams add_module
#' @param method Method to be used for downloading files, 'curl' is default see [utils::download.file()].
#' @rdname favicon
#' @export
#'
#'
#' @importFrom attempt stop_if_not
#' @importFrom fs path_abs path file_copy
#'
#'
#' @return Used for side-effects.
#'
#' @examples
#' if (interactive()){
#' if (interactive()) {
#' use_favicon()
#' use_favicon(path='path/to/your/favicon.ico')
#' use_favicon(path = "path/to/your/favicon.ico")
#' }
use_favicon <- function(
path,
pkg = get_golem_wd(),
method = "curl"
){
if ( missing(path) ){
use_favicon <- function(path,
pkg = get_golem_wd(),
method = "curl") {
if (missing(path)) {
path <- golem_sys("shinyexample/inst/app/www", "favicon.ico")
}
}

ext <- file_ext(path)

stop_if_not(
ext,
~ .x %in% c("png",'ico'),
ext,
~ .x %in% c("png", "ico"),
"favicon must have .ico or .png extension"
)


local <- fs::file_exists(path)

if ( !local ){

if (getRversion() >= "3.5"){
try_online <- attempt::attempt(
curlGetHeaders(path),
silent = TRUE
)
attempt::stop_if(
try_online,
attempt::is_try_error,
"Provided path is neither a local path nor a reachable url."
)

attempt::stop_if_not(
attr(try_online, 'status'),
~ .x == 200,
"Unable to reach provided url (response code is not 200)."
)


if (!local) {
if (getRversion() >= "3.5") {
try_online <- attempt::attempt(
curlGetHeaders(path),
silent = TRUE
)
attempt::stop_if(
try_online,
attempt::is_try_error,
"Provided path is neither a local path nor a reachable url."
)

attempt::stop_if_not(
attr(try_online, "status"),
~ .x == 200,
"Unable to reach provided url (response code is not 200)."
)
}

destfile <- tempfile(
fileext = paste0(".",ext),
fileext = paste0(".", ext),
pattern = "favicon"
)

utils::download.file(
path,
destfile,
path,
destfile,
method = method
)
path <- path_abs(destfile)
}
old <- setwd( path_abs(pkg) )
on.exit( setwd(old) )

old <- setwd(path_abs(pkg))

on.exit(setwd(old))

to <- path(
path_abs(pkg),
path_abs(pkg),
"inst/app/www",
sprintf(
"favicon.%s",
"favicon.%s",
ext
)
)
if (! (path == to) ) {

if (!(path == to)) {
file_copy(
path,
to,
path,
to,
overwrite = TRUE
)
cat_green_tick(
sprintf(
"favicon.%s created at %s",
ext,
"favicon.%s created at %s",
ext,
to
)
)
}
if (ext == "png"){

if (ext == "png") {
cat_red_bullet(
"You choose a png favicon, please add `ext = 'png'` to `favicon()` within the `golem_add_external_resources()` function in 'app_ui.R'."
)
Expand All @@ -107,27 +103,24 @@ use_favicon <- function(
"Favicon is automatically linked in app_ui via `golem_add_external_resources()`"
)
}

}

#' @rdname favicon
#' @export
#' @export
#' @importFrom fs file_delete file_exists
remove_favicon <- function(
path = "inst/app/www/favicon.ico"
){
if (file_exists(path)){
remove_favicon <- function(path = "inst/app/www/favicon.ico") {
if (file_exists(path)) {
cat_green_tick(
sprintf(
"Removing favicon at %s",
"Removing favicon at %s",
path
)
)
file_delete(path)
} else {
cat_red_bullet(
sprintf(
"No file found at %s",
"No file found at %s",
path
)
)
Expand All @@ -137,33 +130,30 @@ remove_favicon <- function(
#' Add favicon to your app
#'
#' This function adds the favicon from `ico` to your shiny app.
#'
#'
#' @param ico path to favicon file
#' @param rel rel
#' @param resources_path prefix of the resource path of the app
#' @param ext the extension of the favicon
#'
#' @export
#' @importFrom htmltools tags
#'
#' @importFrom shiny tags
#'
#' @return An HTML tag.
favicon <- function(
ico = "favicon",
rel="shortcut icon",
resources_path = "www",
ext = "ico"
){

favicon <- function(ico = "favicon",
rel = "shortcut icon",
resources_path = "www",
ext = "ico") {
ico <- fs::path(
resources_path,
ico,
resources_path,
ico,
ext = ext
)

tags$head(
tags$link(
rel = rel,
rel = rel,
href = ico
)
)
}
}
4 changes: 2 additions & 2 deletions man/favicon.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/testhelpers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ea4257

Please sign in to comment.