8000 Create a workflow to render website with Rmarkdown · Issue #971 · r-lib/actions · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Create a workflow to render website with Rmarkdown #971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
berthetclement opened this issue Feb 14, 2025 · 3 comments
Open

Create a workflow to render website with Rmarkdown #971

berthetclement opened this issue Feb 14, 2025 · 3 comments
Labels
feature a feature request or enhancement help wanted ❤️ we'd love your help!

Comments

@berthetclement
Copy link
berthetclement commented Feb 14, 2025

Hello,

I'd like to create a static page or web site from an R project.

Currently I have a project that I started with Rstudio (New Projet->Create a simple R Markdown website).

My problem is that I'm forced to push my site on my github repos for the moment (the site is in docs/ and github deploits correctly from docs/ on master).

Is it possible with git to push on a gh-pages branch only the content of the site (the content of “_site” by default or docs/ for me)?

This would allow me to have a repository with the source code only.

Another question, I haven't tried it yet but I'd like to create a CI/CD that performs a rmarkdown::render_site() and deploys on gh-pages a bit like usethis::use_github_action(“pkgdown”).

Is this possible?

If you have any info on best practices with Rmarkdown simple website for optimal deployment, I'd love to hear from you.

I'll have a solution if what I'm asking for isn't suitable or intended for this. I can also transform my R project into a package and simply use {pkgdown} and deploy with usethis::use_github_action(“pkgdown”).

Thanks a lot!

@berthetclement berthetclement added the feature a feature request or enhancement label Feb 14, 2025
@gaborcsardi gaborcsardi added the help wanted ❤️ we'd love your help! label Feb 19, 2025
@gaborcsardi
Copy link
Member

It is challenging to maintain a lot of workflows that are untested or lightly tested.

Nevertheless, I would be happy to review a PR for such a workflow.

I think it will be very close to https://github.com/r-lib/actions/blob/v2-branch/examples/bookdown.yaml or the other bookdown workflow, but instead of calling render_book(), you'd call rmarkdown::render().

I would probably use pak instead of renv for a new workflow, but YMMV.

@berthetclement
Copy link
Author

Thank you for your feedback, it's much appreciated.

Indeed, I have a workflow very similar to https://github.com/r-lib/actions/blob/v2-branch/examples/bookdown.yaml.

# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples/blogdown.yaml
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
  push:
    branches: [main, master]
  pull_request:
  workflow_dispatch:
  
name: render_site.yaml

permissions: read-all

jobs:
  renderrmarkdown:
    runs-on: ubuntu-latest
    # Only restrict concurrency for non-PR jobs
    concurrency:
      group: renderrmarkdown-${{ github.event_name != 'pull_request' || github.run_id }}
    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4

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

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

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

      - name: Build site
        run: rmarkdown::render_site()
        shell: Rscript {0}

      - name: Deploy to GitHub pages 🚀
        if: github.event_name != 'pull_request'
        uses: JamesIves/github-pages-deploy-action@v4.5.0
        with:
          clean: false
          branch: gh-pages
          folder: docs

But unfortunately I have a problem (with Pandoc) when I build the site with github actions.
Currently, i only try with renv to use r-lib/actions/setup-renv@v2.

My issue :

Run rmarkdown::render_site()
  rmarkdown::render_site()
  shell: /usr/local/bin/Rscript {0}
  env:
    GITHUB_PAT: ***
    R_LIBS_USER: /home/runner/work/_temp/Library
    TZ: UTC
    _R_CHECK_SYSTEM_CLOCK_: FALSE
    NOT_CRAN: true
    RSPM: https://packagemanager.posit.co/cran/__linux__/noble/latest
    RENV_CONFIG_REPOS_OVERRIDE: https://packagemanager.posit.co/cran/__linux__/noble/latest
    RENV_PATHS_ROOT: /home/runner/work/_temp/renv
- The project is out-of-sync -- use `renv::status()` for details.

Rendering: ./dashboard.Rmd
1/11                  
[2](https://github.com/rte-antares-rpackage/rPackagesRte/actions/runs/13416350141/job/37478027901#step:6:2)/11 [setup]          
3/11                  
4/11 [unnamed-chunk-1]
5/11                  
6/11 [unnamed-chunk-2]
7/11                  
8/11 [unnamed-chunk-[3](https://github.com/rte-antares-rpackage/rPackagesRte/actions/runs/13416350141/job/37478027901#step:6:3)]
9/11                  
10/11 [unnamed-chunk-[4](https://github.com/rte-antares-rpackage/rPackagesRte/actions/runs/13416350141/job/37478027901#step:6:4)]
Error in `format$format == "pandoc" && nzchar(format$caption)`:
! 'length = 6' in coercion to 'logical(1)'
Backtrace:
  1. rmarkdown::render_site()
  2. generator$render(...)
  3. base::sapply(...)
  4. base::lapply(X = X, FUN = FUN, ...)
  [5](https://github.com/rte-antares-rpackage/rPackagesRte/actions/runs/13416350141/job/37478027901#step:6:5). rmarkdown (local) FUN(X[[i]], ...)
     ...
 27. knitr (local) value_fun(ev$value, ev$visible)
 2[8](https://github.com/rte-antares-rpackage/rPackagesRte/actions/runs/13416350141/job/37478027901#step:6:8). knitr (local) fun(x, options = options)
 31. formattable:::knit_print.formattable(x, ...)
 33. formattable:::knit_print_formattable.data.frame(x, ...)
 34. base::isTRUE(format$format == "pandoc" && nzchar(format$caption))
Execution halted
Error: Process completed with exit code 1.

I can build the site locally without any problem (using renv or not):

sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.utf8  LC_CTYPE=French_France.utf8    LC_MONETARY=French_France.utf8 LC_NUMERIC=C                  
[5] LC_TIME=French_France.utf8    

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
 [1] yaml_2.3.8          shiny_1.8.1.1       htmltools_0.5.8.1   gfonts_0.2.0        particlesjs_0.1.1   shufflecards_0.0.4 
 [7] jsonlite_1.8.8      httr_1.4.7          gh_1.4.1            formattable_0.2.1   flexdashboard_0.6.2

loaded via a namespace (and not attached):
 [1] xfun_0.43         httr2_1.0.1       bslib_0.7.0       purrr_1.0.2       colorspace_2.1-0  vctrs_0.6.5      
 [7] utf8_1.2.4        rlang_1.1.4       jquerylib_0.1.4   pillar_1.9.0      later_1.3.2       httpcode_0.3.0   
[13] glue_1.7.0        rappdirs_0.3.3    uuid_1.2-0        lifecycle_1.0.4   munsell_0.5.1     gtable_0.3.5     
[19] fontawesome_0.5.2 htmlwidgets_1.6.4 memoise_2.0.1     evaluate_0.23     knitr_1.46        fastmap_1.1.1    
[25] httpuv_1.6.15     crosstalk_1.2.1   curl_6.1.0        fansi_1.0.6       ggiraph_0.8.12    Rcpp_1.0.12      
[31] xtable_1.8-4      renv_1.0.11       scales_1.3.0      promises_1.3.0    cachem_1.0.8      mime_0.12        
[37] systemfonts_1.0.6 ggplot2_3.5.1     digest_0.6.35     grid_4.2.2        cli_3.6.2         tools_4.2.2      
[43] magrittr_2.0.3    sass_0.4.9        tibble_3.2.1      crul_1.4.2        crayon_1.5.2      pkgconfig_2.0.3  
[49] rmarkdown_2.29    rstudioapi_0.16.0 R6_2.5.1          gitcreds_0.1.2    compiler_4.2.2   

I think that for this to work, I'd turn my project into a package and use https://github.com/r-lib/actions/blob/v2-branch/examples/pkgdown.yaml or maybe test quarto ....

In any case, I publish my static site from the /docs master but it's not satisfactory.

Thanks for your feedback!

@gaborcsardi
Copy link
Member

This is coming from your code in the Rmd, so I suggest you try something very simple first, just to get the tooling right, and then use the full Rmd.

It might be easier to debug this interactively, one action that can help you with that is https://github.com/r-hub/actions/tree/main/debug-shell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement help wanted ❤️ we'd love your help!
Projects
None yet
Development

No branches or pull requests

2 participants
0