Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 19 additions & 52 deletions .github/workflows/check-standard.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
on:
push:
branches:
- master
branches: [main, master]
pull_request:
branches:
- master
branches: [main, master]

name: R-CMD-check

Expand All @@ -18,62 +17,30 @@ jobs:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: '3.6'}
- {os: macOS-latest, r: '3.6'}
- {os: macOS-latest, r: 'devel'}
- {os: ubuntu-16.04, r: '3.6', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-latest, r: 'release'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

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

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
use-public-rspm: true

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

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-

- name: Install system dependencies
if: runner.os == 'Linux'
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}
extra-packages: any::rcmdcheck
needs: check

- name: Upload check results
if: failure()
uses: actions/upload-artifact@master
- uses: r-lib/actions/check-r-package@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
upload-snapshots: true
args: 'c("--no-manual", "--as-cran", "--no-vignettes")'
build_args: 'c("--no-manual", "--no-build-vignettes")'
error-on: '"error"'
8 changes: 4 additions & 4 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
pkgdown:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

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

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

- name: Query dependencies
run: |
Expand All @@ -21,7 +21,7 @@ jobs:
shell: Rscript {0}

- name: Cache R packages
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ${{ env.R_LIBS_USER }}
key: macOS-r-3.6-${{ hashFiles('.github/depends.Rds') }}
Expand Down
27 changes: 17 additions & 10 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ file.copy(list.files("reference/figures", full.names = TRUE),

The goal of shinysnippets is to save development time while taking advantage of Rstudio snippets for Shiny applications.

![](man/figures/best_rstudio_snippet.gif)

## Installation of snippets

### Via the package
Expand Down Expand Up @@ -61,22 +63,27 @@ Copy and paste these snippets to Tools > Global Options > Code > Editing > Edit

```{}
snippet module
${1:name}ui <- function(id){
${1:name}_ui <- function(id){
ns <- NS(id)
tagList(

)
}

${1:name} <- function(input, output, session){
ns <- session\$ns
)
}


${1:name}_server <- function(id){
moduleServer(
id,
function(input, output, session){
ns <- session\$ns
}
)
}

# Copy in UI
${1:name}ui("${1:name}ui")
${1:name}_ui("${1:name}_1")

# Copy in server
callModule(${1:name}, "${1:name}ui")
${1:name}_server("${1:name}_1")
```

![](man/figures/module_snippet.gif)
Expand Down
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ status](https://github.com/ThinkR-open/shinysnippets/workflows/R-CMD-check/badge
The goal of shinysnippets is to save development time while taking
advantage of Rstudio snippets for Shiny applications.

![](man/figures/best_rstudio_snippet.gif)

## Installation of snippets

### Via the package
Expand Down Expand Up @@ -43,22 +45,27 @@ Editing \> Edit Snippets.
### Modules

snippet module
${1:name}ui <- function(id){
${1:name}_ui <- function(id){
ns <- NS(id)
tagList(
)
}

)
}

${1:name} <- function(input, output, session){
ns <- session\$ns
${1:name}_server <- function(id){
moduleServer(
id,
function(input, output, session){
ns <- session\$ns
}
)
}

# Copy in UI
${1:name}ui("${1:name}ui")
${1:name}_ui("${1:name}_1")

# Copy in server
callModule(${1:name}, "${1:name}ui")
${1:name}_server("${1:name}_1")

![](man/figures/module_snippet.gif)

Expand Down
28 changes: 17 additions & 11 deletions inst/snippets.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
snippet module
${1:name}ui <- function(id){
${1:name}_ui <- function(id){
ns <- NS(id)
tagList(
${0}
)
}
${2}
)
}

${1:name} <- function(input, output, session){
ns <- session\$ns
${1:name}_server <- function(id){
moduleServer(
id,
function(input, output, session){
ns <- session\$ns
${0}
}
)
}

# Copy in UI
#${1:name}ui("${1:name}ui")
#${1:name}_ui("${1:name}_1")

# Copy in server
#callModule(${1:name}, "${1:name}ui")
#${1:name}_server("${1:name}_1")

snippet observe_event
observeEvent( ${1:event} , {
${0}
Expand Down
Binary file added man/figures/best_rstudio_snippet.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions tests/testthat/test-snippet.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})

test_that("module snippet uses the modern moduleServer API (#14)", {
path <- system.file("snippets.txt", package = "shinysnippets")
if (!nzchar(path)) skip("shinysnippets package not installed")
txt <- paste(readLines(path), collapse = "\n")

expect_true(
grepl("moduleServer", txt, fixed = TRUE),
info = "module snippet should use moduleServer()"
)
expect_false(
grepl("callModule", txt, fixed = TRUE),
info = "module snippet should no longer use deprecated callModule()"
)
expect_true(
grepl("function(input, output, session)", txt, fixed = TRUE),
info = "module snippet should keep the server function signature"
)
# The final tabstop ${0} must land in the server body so users can type
# the module logic right after expanding the snippet.
server_chunk <- regmatches(
txt,
regexpr(
"function\\(input, output, session\\)\\{[\\s\\S]*?\\}",
txt,
perl = TRUE
)
)
expect_true(
length(server_chunk) == 1L && grepl("${0}", server_chunk, fixed = TRUE),
info = "module snippet should expose ${0} inside the moduleServer body"
)
})
Loading