Skip to content

Commit

Permalink
Merge pull request #19 from miraisolutions/feature/16-fix-deployment-…
Browse files Browse the repository at this point in the history
…update-renv-rsconnect

Fix deployment with updated renv/rsconnect
  • Loading branch information
riccardoporreca authored Jan 24, 2024
2 parents 1e1b919 + 46abf7e commit ea753f1
Show file tree
Hide file tree
Showing 13 changed files with 685 additions and 577 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ $run_dev.*
^LICENSE\.md$
^README\.Rmd$
^app\.R$
^R/_disable_autoload\.R$
^rsconnect$
^\.rscignore$
^\.github$
^deploy$
28 changes: 18 additions & 10 deletions .github/workflows/ci-cd-renv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ on:
schedule:
- cron: '0 0 1 * *'

# Avoid concurrent deployments from both workflows by running one at a time
# (specific for ShinyCICD maintenance)
concurrency:
group: shinyapps-${{ github.ref }}

jobs:
CI-CD:
runs-on: ${{ matrix.config.os }}
Expand All @@ -26,7 +31,7 @@ jobs:
# single OS and R version, aligned with the target deployment environment
matrix:
config:
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'renv'}

env:
# Access token for GitHub
Expand All @@ -43,18 +48,21 @@ jobs:
uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
# Enable RStudio Package Manager to speed up package installation
use-public-rspm: true
# No RStudio Package Manager to respect renv.lock
use-public-rspm: false

- name: Install system dependencies
# This is not taken care of (yet) by r-lib/actions/setup-renv
# Package distro used to get the distro for the used ubuntu-latest
# See https://github.com/r-lib/actions/issues/785
run: |
Rscript -e "install.packages(c('remotes', 'distro'))"
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(with(distro::distro(), remotes::system_requirements(id, short_version)))')
# We rely on pkgdepends from the library embedded in pak
install.packages("pak", repos = "https://r-lib.github.io/p/pak/stable/")
install.packages("jsonlite")
.libPaths(c(system.file("library", package = "pak"), .libPaths()))
pkgdepends::new_pkg_installation_proposal(
names(jsonlite::read_json("renv.lock")$Packages), config = list(dependencies = FALSE)
)$solve()$install_sysreqs()
shell: Rscript {0}

- name: Activate renv and restore packages with cache
uses: r-lib/actions/setup-renv@v2
Expand All @@ -68,7 +76,7 @@ jobs:

- name: Deploy to shinyapps.io
# Continuous deployment only for pushes to the main / master branch
if: false && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
env:
SHINYAPPS_ACCOUNT: ${{ secrets.SHINYAPPS_ACCOUNT }}
SHINYAPPS_TOKEN: ${{ secrets.SHINYAPPS_TOKEN }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ on:
schedule:
- cron: '0 0 1 * *'

# Avoid concurrent deployments from both workflows by running one at a time
# (specific for ShinyCICD maintenance)
concurrency:
group: shinyapps-${{ github.ref }}

jobs:
CI-CD:
runs-on: ${{ matrix.config.os }}
Expand Down
1 change: 1 addition & 0 deletions .rscignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
renv.lock
3 changes: 3 additions & 0 deletions R/_disable_autoload.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Disabling shiny autoload

# See ?shiny::loadSupport for more information
2 changes: 1 addition & 1 deletion R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
app_server <- function(input, output, session) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
x <- datasets::faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)

# draw the histogram with the specified number of bins
Expand Down
4 changes: 2 additions & 2 deletions ShinyCICD.Rproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
Expand Down
22 changes: 17 additions & 5 deletions deploy/deploy-shinyapps.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
# deploy/deploy-shinyapps.R
# usethis::use_build_ignore("deploy")
rsconnect::setAccountInfo(
Sys.getenv("SHINYAPPS_ACCOUNT"),
Sys.getenv("SHINYAPPS_TOKEN"),
Sys.getenv("SHINYAPPS_SECRET")
if (!interactive()) {
rsconnect::setAccountInfo(
Sys.getenv("SHINYAPPS_ACCOUNT"),
Sys.getenv("SHINYAPPS_TOKEN"),
Sys.getenv("SHINYAPPS_SECRET")
)
}
# Add here any additional files/directories the app needs
app_files = c(
"app.R",
"DESCRIPTION",
"NAMESPACE",
"R/",
"inst/"
)
rsconnect::deployApp(
appName = "ShinyCICD", appFiles = app_files, forceUpdate = TRUE
)
rsconnect::deployApp(appName = "ShinyCICD")
Loading

0 comments on commit ea753f1

Please sign in to comment.