Skip to content

Commit

Permalink
Merge pull request #33 from Appsilon/develop
Browse files Browse the repository at this point in the history
Release v0.2.0
  • Loading branch information
kamilzyla authored Feb 14, 2022
2 parents 3dc6f37 + 051d784 commit 1552be6
Show file tree
Hide file tree
Showing 18 changed files with 289 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ jobs:
shell: Rscript {0}

- name: Lint
run: lintr::lint_package()
run: |
lintr::lint_package()
shell: Rscript {0}

- name: Upload lint results
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
- main
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Deploy to gh-pages branch
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
4 changes: 3 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
linters: with_defaults(
line_length_linter = line_length_linter(100)
line_length_linter = line_length_linter(100),
infix_spaces_linter = NULL,
object_usage_linter = NULL
)
9 changes: 7 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rhino
Title: A framework for enterprise Shiny applications
Version: 0.1.0
Version: 0.2.0
Authors@R:
c(
person(given = "Kamil", family = "Zyla", role = "aut", email = "[email protected]"),
Expand All @@ -11,12 +11,17 @@ Authors@R:
person(family = "Appsilon Sp. z o.o.", role = "cph")
)
Description: A framework that supports creating and extending enterprise Shiny applications using best practices.
URL: https://github.com/Appsilon/rhino
URL: https://appsilon.github.io/rhino, https://github.com/Appsilon/rhino
BugReports: https://github.com/Appsilon/rhino/issues
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
Imports:
fs,
cli,
renv,
withr
Suggests:
lintr (>= 2.0.0),
testthat (>= 3.0.0)
Expand Down
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# Generated by roxygen2: do not edit by hand

export(init)
importFrom(cli,cli_alert_success)
importFrom(fs,dir_copy)
importFrom(fs,dir_create)
importFrom(fs,file_copy)
importFrom(fs,path)
importFrom(fs,path_package)
importFrom(renv,init)
importFrom(withr,with_dir)
Empty file removed R/.gitkeep
Empty file.
93 changes: 93 additions & 0 deletions R/init.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#' Create Shiny application using `{rhino}`
#'
#' @param dir Name of the directory to create application in.
#' @param github_actions_ci Should the Github Actions CI be added.
#'
#' @export
init <- function(dir = ".", github_actions_ci = TRUE) {
init_setup(dir)

create_app_structure(dir)

if (isTRUE(github_actions_ci)) add_github_actions_ci(dir)

init_renv(dir)
}

#' @importFrom fs dir_create
#' @importFrom cli cli_alert_success
init_setup <- function(dir) {
dir_create(dir)
cli_alert_success("Application directory created")
}

#' @importFrom fs dir_copy file_copy path
#' @importFrom cli cli_alert_success
create_app_structure <- function(dir) {
file_copy(
path = path_rhino("app_structure", "app.R"),
new_path = dir
)

file_copy(
path = path_rhino("app_structure", "Rprofile"),
new_path = path(dir, ".Rprofile")
)

file_copy(
path = path_rhino("app_structure", "src.Rproj2"),
new_path = path(dir, "src.Rproj")
)

dir_copy(
path = path_rhino("app_structure", "app"),
new_path = dir
)

cli_alert_success("Application structure created")
}

#' @importFrom fs dir_create dir_copy path
#' @importFrom cli cli_alert_success
add_github_actions_ci <- function(dir) {
github_path <- path(dir, ".github")
dir_create(github_path)
dir_copy(
path = path_rhino("github_ci", "workflows"),
new_path = github_path
)

cli_alert_success("Github Actions CI added")
}

#' @importFrom fs file_copy
#' @importFrom renv init
#' @importFrom withr with_dir
#' @importFrom cli cli_alert_success
init_renv <- function(dir) {
file_copy(
path = path_rhino("renv", "renvignore"),
new_path = path(dir, ".renvignore")
)

file_copy(
path = path_rhino("renv", "dependencies.R"),
new_path = path(dir)
)

with_dir(
dir,
renv::init(restart = FALSE)
)

cli_alert_success("renv initiated")
}

#' @importFrom fs path_package
path_rhino <- function(...) {
path_package(
"rhino",
"templates",
...
)
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ Alternatively, the package can be installed, and then tested with `testthat::tes

#### Linter
Linter can be run using either `lintr::lint_package()` or `devtools::lint()`.

#### `pkgdown` site
To create a `pkgdown` site locally run either `pkgdown::build_site()` or `devtools::build_site()`.
If built successfully, the website will be in `docs` directory.
7 changes: 7 additions & 0 deletions inst/rstudio/templates/project/init.dcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Binding: init
Title: Shiny Application using rhino

Parameter: github_actions_ci
Widget: CheckboxInput
Label: Github Actions CI
Default: On
2 changes: 2 additions & 0 deletions inst/templates/app_structure/Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Allow absolute module imports (relative to the app root).
options(box.path = file.path(getwd(), "app"))
29 changes: 29 additions & 0 deletions inst/templates/app_structure/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Purge the box module cache, so the app can be reloaded without restarting the R session.
rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods)

box::use(
logger[appender_file, log_appender, log_threshold],
shiny[addResourcePath, shinyApp],
)
box::use(
r/main,
)

# nolint start
LOG_FILE <- Sys.getenv("LOG_FILE")
LOG_LEVEL <- Sys.getenv("LOG_LEVEL", unset = "INFO")
# nolint end

addResourcePath("static", "app/static")

log_threshold(LOG_LEVEL)
if (nzchar(LOG_FILE)) {
log_appender(appender_file(LOG_FILE))
}

shinyApp(
ui = main$ui("app"),
server = function(input, output) {
main$server("app")
}
)
23 changes: 23 additions & 0 deletions inst/templates/app_structure/app/r/main.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
box::use(
shiny[bootstrapPage, moduleServer, NS, renderText, tags, textOutput],
)

#' @export
ui <- function(id) {
ns <- NS(id)
bootstrapPage(
tags$head(
tags$link(rel = "icon", href = "static/favicon.ico", sizes = "any")
),
tags$h3(
textOutput(ns("message"))
)
)
}

#' @export
server <- function(id) {
moduleServer(id, function(input, output, session) {
output$message <- renderText("Hello!")
})
}
Binary file not shown.
13 changes: 13 additions & 0 deletions inst/templates/app_structure/src.Rproj2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
33 changes: 33 additions & 0 deletions inst/templates/github_ci/workflows/linter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Linter
on: push
jobs:
main:
name: Run linter
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Setup R
uses: r-lib/actions/setup-r@v1
with:
r-version: '4.1.0'

- name: Restore renv from cache
uses: actions/cache@v2
with:
path: renv/library
key: renv-${{ hashFiles('renv.lock') }}
restore-keys: renv-

- name: Sync renv with lockfile
shell: Rscript {0}
run: |
options(renv.config.cache.symlinks = FALSE)
renv::restore(clean = TRUE)
- name: Lint R
if: always()
shell: Rscript {0}
run: |
rhino::lint_r()
11 changes: 11 additions & 0 deletions inst/templates/renv/dependencies.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file allows packrat (used by rsconnect during deployment) to pick up dependencies.

# Development
library(lintr)
library(yaml) # Used to load config for lintr.

# Production
library(box)
library(logger)
library(shiny)
library(rhino)
3 changes: 3 additions & 0 deletions inst/templates/renv/renvignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Only use `dependencies.R` to infer project dependencies.
*
!dependencies.R
16 changes: 16 additions & 0 deletions man/init.Rd

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

0 comments on commit 1552be6

Please sign in to comment.