diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..4341958 --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,6 @@ +^.*\.Rproj$ +^\.Rproj\.user$ +^data-raw$ +dev_history.R +^dev$ +$run_dev.* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..565f2b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.Rproj.user +.Rhistory +.Rdata +.httr-oauth +.DS_Store diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..ea53f49 --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,17 @@ +Package: chatgptimages +Title: An Amazing Shiny App +Version: 0.0.0.9000 +Authors@R: + person(given = "firstname", + family = "lastname", + role = c("aut", "cre"), + email = "your@email.com") +Description: What the package does (one paragraph). +License: What license is it under? +Imports: + config (>= 0.3.1), + golem (>= 0.3.5), + shiny (>= 1.7.4) +Encoding: UTF-8 +LazyData: true +RoxygenNote: 7.1.1 diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..2b8d54c --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,10 @@ +# Generated by roxygen2: do not edit by hand + +export(run_app) +import(shiny) +importFrom(golem,activate_js) +importFrom(golem,add_resource_path) +importFrom(golem,bundle_resources) +importFrom(golem,favicon) +importFrom(golem,with_golem_options) +importFrom(shiny,shinyApp) diff --git a/R/app_config.R b/R/app_config.R new file mode 100644 index 0000000..c4381c5 --- /dev/null +++ b/R/app_config.R @@ -0,0 +1,44 @@ +#' Access files in the current app +#' +#' NOTE: If you manually change your package name in the DESCRIPTION, +#' don't forget to change it here too, and in the config file. +#' For a safer name change mechanism, use the `golem::set_golem_name()` function. +#' +#' @param ... character vectors, specifying subdirectory and file(s) +#' within your package. The default, none, returns the root of the app. +#' +#' @noRd +app_sys <- function(...) { + system.file(..., package = "chatgptimages") +} + + +#' Read App Config +#' +#' @param value Value to retrieve from the config file. +#' @param config GOLEM_CONFIG_ACTIVE value. If unset, R_CONFIG_ACTIVE. +#' If unset, "default". +#' @param use_parent Logical, scan the parent directory for config file. +#' @param file Location of the config file +#' +#' @noRd +get_golem_config <- function( + value, + config = Sys.getenv( + "GOLEM_CONFIG_ACTIVE", + Sys.getenv( + "R_CONFIG_ACTIVE", + "default" + ) + ), + use_parent = TRUE, + # Modify this if your config file is somewhere else + file = app_sys("golem-config.yml") +) { + config::get( + value = value, + config = config, + file = file, + use_parent = use_parent + ) +} diff --git a/R/app_server.R b/R/app_server.R new file mode 100644 index 0000000..f431311 --- /dev/null +++ b/R/app_server.R @@ -0,0 +1,9 @@ +#' The application server-side +#' +#' @param input,output,session Internal parameters for {shiny}. +#' DO NOT REMOVE. +#' @import shiny +#' @noRd +app_server <- function(input, output, session) { + # Your application server logic +} diff --git a/R/app_ui.R b/R/app_ui.R new file mode 100644 index 0000000..bd3c0fe --- /dev/null +++ b/R/app_ui.R @@ -0,0 +1,41 @@ +#' The application User-Interface +#' +#' @param request Internal parameter for `{shiny}`. +#' DO NOT REMOVE. +#' @import shiny +#' @noRd +app_ui <- function(request) { + tagList( + # Leave this function for adding external resources + golem_add_external_resources(), + # Your application UI logic + fluidPage( + h1("chatgptimages") + ) + ) +} + +#' Add external Resources to the Application +#' +#' This function is internally used to add external +#' resources inside the Shiny application. +#' +#' @import shiny +#' @importFrom golem add_resource_path activate_js favicon bundle_resources +#' @noRd +golem_add_external_resources <- function() { + add_resource_path( + "www", + app_sys("app/www") + ) + + tags$head( + favicon(), + bundle_resources( + path = app_sys("app/www"), + app_title = "chatgptimages" + ) + # Add here other external resources + # for example, you can add shinyalert::useShinyalert() + ) +} diff --git a/R/run_app.R b/R/run_app.R new file mode 100644 index 0000000..5d60ac1 --- /dev/null +++ b/R/run_app.R @@ -0,0 +1,28 @@ +#' Run the Shiny Application +#' +#' @param ... arguments to pass to golem_opts. +#' See `?golem::get_golem_options` for more details. +#' @inheritParams shiny::shinyApp +#' +#' @export +#' @importFrom shiny shinyApp +#' @importFrom golem with_golem_options +run_app <- function( + onStart = NULL, + options = list(), + enableBookmarking = NULL, + uiPattern = "/", + ... +) { + with_golem_options( + app = shinyApp( + ui = app_ui, + server = app_server, + onStart = onStart, + options = options, + enableBookmarking = enableBookmarking, + uiPattern = uiPattern + ), + golem_opts = list(...) + ) +} diff --git a/chatgptimages.Rproj b/chatgptimages.Rproj new file mode 100644 index 0000000..6a3ede2 --- /dev/null +++ b/chatgptimages.Rproj @@ -0,0 +1,21 @@ +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes +LineEndingConversion: Posix + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source diff --git a/dev/01_start.R b/dev/01_start.R new file mode 100644 index 0000000..ea03648 --- /dev/null +++ b/dev/01_start.R @@ -0,0 +1,63 @@ +# Building a Prod-Ready, Robust Shiny Application. +# +# README: each step of the dev files is optional, and you don't have to +# fill every dev scripts before getting started. +# 01_start.R should be filled at start. +# 02_dev.R should be used to keep track of your development during the project. +# 03_deploy.R should be used once you need to deploy your app. +# +# +######################################## +#### CURRENT FILE: ON START SCRIPT ##### +######################################## + +## Fill the DESCRIPTION ---- +## Add meta data about your application +## +## /!\ Note: if you want to change the name of your app during development, +## either re-run this function, call golem::set_golem_name(), or don't forget +## to change the name in the app_sys() function in app_config.R /!\ +## +golem::fill_desc( + pkg_name = "chatgptimages", # The Name of the package containing the App + pkg_title = "A 'Shiny' App for creating images with ChatGPT", # The Title of the package containing the App + pkg_description = "PKG_DESC.", # The Description of the package containing the App + author_first_name = "AUTHOR_FIRST", # Your First Name + author_last_name = "AUTHOR_LAST", # Your Last Name + author_email = "AUTHOR@MAIL.COM", # Your Email + repo_url = NULL # The URL of the GitHub Repo (optional) +) + +## Set {golem} options ---- +golem::set_golem_options() + +## Create Common Files ---- +## See ?usethis for more information +usethis::use_mit_license("Golem User") # You can set another license here +usethis::use_readme_rmd(open = FALSE) +# Note that `contact` is required since usethis version 2.1.5 +# If your {usethis} version is older, you can remove that param +usethis::use_code_of_conduct(contact = "Golem User") +usethis::use_lifecycle_badge("Experimental") +usethis::use_news_md(open = FALSE) + +## Use git ---- +usethis::use_git() + +## Init Testing Infrastructure ---- +## Create a template for tests +golem::use_recommended_tests() + +## Favicon ---- +# If you want to change the favicon (default is golem's one) +golem::use_favicon() # path = "path/to/ico". Can be an online file. +# golem::remove_favicon() # Uncomment to remove the default favicon + +## Add helper functions ---- +golem::use_utils_ui(with_test = TRUE) +golem::use_utils_server(with_test = TRUE) + +# You're now set! ---- + +# go to dev/02_dev.R +rstudioapi::navigateToFile("dev/02_dev.R") diff --git a/dev/02_dev.R b/dev/02_dev.R new file mode 100644 index 0000000..65152a0 --- /dev/null +++ b/dev/02_dev.R @@ -0,0 +1,96 @@ +# Building a Prod-Ready, Robust Shiny Application. +# +# README: each step of the dev files is optional, and you don't have to +# fill every dev scripts before getting started. +# 01_start.R should be filled at start. +# 02_dev.R should be used to keep track of your development during the project. +# 03_deploy.R should be used once you need to deploy your app. +# +# +################################### +#### CURRENT FILE: DEV SCRIPT ##### +################################### + +# Engineering + +## Dependencies ---- +## Amend DESCRIPTION with dependencies read from package code parsing +## install.package('attachment') # if needed. +attachment::att_amend_desc() + +## Add modules ---- +## Create a module infrastructure in R/ +golem::add_module(name = "name_of_module1", with_test = TRUE) # Name of the module +golem::add_module(name = "name_of_module2", with_test = TRUE) # Name of the module + +## Add helper functions ---- +## Creates fct_* and utils_* +golem::add_fct("helpers", with_test = TRUE) +golem::add_utils("helpers", with_test = TRUE) + +## External resources +## Creates .js and .css files at inst/app/www +golem::add_js_file("script") +golem::add_js_handler("handlers") +golem::add_css_file("custom") +golem::add_sass_file("custom") + +## Add internal datasets ---- +## If you have data in your package +usethis::use_data_raw(name = "my_dataset", open = FALSE) + +## Tests ---- +## Add one line by test you want to create +usethis::use_test("app") + +# Documentation + +## Vignette ---- +usethis::use_vignette("chatgptimages") +devtools::build_vignettes() + +## Code Coverage---- +## Set the code coverage service ("codecov" or "coveralls") +usethis::use_coverage() + +# Create a summary readme for the testthat subdirectory +covrpage::covrpage() + +## CI ---- +## Use this part of the script if you need to set up a CI +## service for your application +## +## (You'll need GitHub there) +usethis::use_github() + +# GitHub Actions +usethis::use_github_action() +# Chose one of the three +# See https://usethis.r-lib.org/reference/use_github_action.html +usethis::use_github_action_check_release() +usethis::use_github_action_check_standard() +usethis::use_github_action_check_full() +# Add action for PR +usethis::use_github_action_pr_commands() + +# Travis CI +usethis::use_travis() +usethis::use_travis_badge() + +# AppVeyor +usethis::use_appveyor() +usethis::use_appveyor_badge() + +# Circle CI +usethis::use_circleci() +usethis::use_circleci_badge() + +# Jenkins +usethis::use_jenkins() + +# GitLab CI +usethis::use_gitlab_ci() + +# You're now set! ---- +# go to dev/03_deploy.R +rstudioapi::navigateToFile("dev/03_deploy.R") diff --git a/dev/03_deploy.R b/dev/03_deploy.R new file mode 100644 index 0000000..2f9595e --- /dev/null +++ b/dev/03_deploy.R @@ -0,0 +1,40 @@ +# Building a Prod-Ready, Robust Shiny Application. +# +# README: each step of the dev files is optional, and you don't have to +# fill every dev scripts before getting started. +# 01_start.R should be filled at start. +# 02_dev.R should be used to keep track of your development during the project. +# 03_deploy.R should be used once you need to deploy your app. +# +# +###################################### +#### CURRENT FILE: DEPLOY SCRIPT ##### +###################################### + +# Test your app + +## Run checks ---- +## Check the package before sending to prod +devtools::check() +rhub::check_for_cran() + +# Deploy + +## Local, CRAN or Package Manager ---- +## This will build a tar.gz that can be installed locally, +## sent to CRAN, or to a package manager +devtools::build() + +## RStudio ---- +## If you want to deploy on RStudio related platforms +golem::add_rstudioconnect_file() +golem::add_shinyappsio_file() +golem::add_shinyserver_file() + +## Docker ---- +## If you want to deploy via a generic Dockerfile +golem::add_dockerfile_with_renv() + +## If you want to deploy to ShinyProxy +golem::add_dockerfile_with_renv_shinyproxy() + diff --git a/dev/run_dev.R b/dev/run_dev.R new file mode 100644 index 0000000..08030f4 --- /dev/null +++ b/dev/run_dev.R @@ -0,0 +1,15 @@ +# Set options here +options(golem.app.prod = FALSE) # TRUE = production mode, FALSE = development mode + +# Comment this if you don't want the app to be served on a random port +options(shiny.port = httpuv::randomPort()) + +# Detach all loaded packages and clean your environment +golem::detach_all_attached() +# rm(list=ls(all.names = TRUE)) + +# Document and reload your package +golem::document_and_reload() + +# Run the application +run_app() diff --git a/inst/app/www/favicon.ico b/inst/app/www/favicon.ico new file mode 100644 index 0000000..4c0982c Binary files /dev/null and b/inst/app/www/favicon.ico differ diff --git a/inst/golem-config.yml b/inst/golem-config.yml new file mode 100644 index 0000000..10f5059 --- /dev/null +++ b/inst/golem-config.yml @@ -0,0 +1,8 @@ +default: + golem_name: chatgptimages + golem_version: 0.0.0.9000 + app_prod: no +production: + app_prod: yes +dev: + golem_wd: !expr here::here() diff --git a/man/run_app.Rd b/man/run_app.Rd new file mode 100644 index 0000000..6be75ea --- /dev/null +++ b/man/run_app.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/run_app.R +\name{run_app} +\alias{run_app} +\title{Run the Shiny Application} +\usage{ +run_app( + onStart = NULL, + options = list(), + enableBookmarking = NULL, + uiPattern = "/", + ... +) +} +\arguments{ +\item{onStart}{A function that will be called before the app is actually run. +This is only needed for \code{shinyAppObj}, since in the \code{shinyAppDir} +case, a \code{global.R} file can be used for this purpose.} + +\item{options}{Named options that should be passed to the \code{runApp} call +(these can be any of the following: "port", "launch.browser", "host", "quiet", +"display.mode" and "test.mode"). You can also specify \code{width} and +\code{height} parameters which provide a hint to the embedding environment +about the ideal height/width for the app.} + +\item{enableBookmarking}{Can be one of \code{"url"}, \code{"server"}, or +\code{"disable"}. The default value, \code{NULL}, will respect the setting from +any previous calls to \code{\link[shiny:enableBookmarking]{enableBookmarking()}}. See \code{\link[shiny:enableBookmarking]{enableBookmarking()}} +for more information on bookmarking your app.} + +\item{uiPattern}{A regular expression that will be applied to each \code{GET} +request to determine whether the \code{ui} should be used to handle the +request. Note that the entire request path must match the regular +expression in order for the match to be considered successful.} + +\item{...}{arguments to pass to golem_opts. +See `?golem::get_golem_options` for more details.} +} +\description{ +Run the Shiny Application +}