diff --git a/.github/workflows/check-standard.yaml b/.github/workflows/check-standard.yaml index 39b7866..a0d151f 100644 --- a/.github/workflows/check-standard.yaml +++ b/.github/workflows/check-standard.yaml @@ -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 @@ -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"' diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index bbef6ce..c7c73bb 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -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: | @@ -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') }} diff --git a/README.Rmd b/README.Rmd index 1ab63a2..1576cad 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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 @@ -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) diff --git a/README.md b/README.md index 1962385..832415f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) diff --git a/inst/snippets.txt b/inst/snippets.txt index 0868d34..da4b895 100644 --- a/inst/snippets.txt +++ b/inst/snippets.txt @@ -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} diff --git a/man/figures/best_rstudio_snippet.gif b/man/figures/best_rstudio_snippet.gif new file mode 100644 index 0000000..0c26917 Binary files /dev/null and b/man/figures/best_rstudio_snippet.gif differ diff --git a/tests/testthat/test-snippet.R b/tests/testthat/test-snippet.R index 8849056..ca0c70a 100644 --- a/tests/testthat/test-snippet.R +++ b/tests/testthat/test-snippet.R @@ -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" + ) +})