├── .Rbuildignore ├── .gitattributes ├── .github ├── .gitignore ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── todo.md └── workflows │ ├── R-CMD-check.yaml │ ├── pkgdown.yaml │ ├── pr-commands.yaml │ ├── recheck.yml │ ├── render-rmarkdown-and-bump-version.yaml │ ├── rhub.yaml │ └── test-coverage.yaml ├── .gitignore ├── .pre-commit-config.yaml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CRAN-SUBMISSION ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── add_dockerfiles.R ├── add_dockerfiles_renv.R ├── add_files.R ├── add_r_files.R ├── add_resource_path.R ├── add_rstudio_files.R ├── addins.R ├── boostrap_base.R ├── boostrap_cli.R ├── boostrap_crayon.R ├── boostrap_fs.R ├── bootstrap_attachment.R ├── bootstrap_desc.R ├── bootstrap_dockerfiler.R ├── bootstrap_pkgload.R ├── bootstrap_rlang.R ├── bootstrap_roxygen2.R ├── bootstrap_rstudio_api.R ├── bootstrap_testthat.R ├── bootstrap_usethis.R ├── browser_button.R ├── bundle_resources.R ├── cats.R ├── cli_msg.R ├── config.R ├── create_golem.R ├── desc.R ├── disable_autoload.R ├── enable_roxygenize.R ├── get_sysreqs.R ├── globals.R ├── golem-package.R ├── golem-yaml-get.R ├── golem-yaml-set.R ├── golem-yaml-utils.R ├── golem_welcome_page.R ├── install_dev_deps.R ├── is_golem.R ├── is_running.R ├── js.R ├── maintenance_page.R ├── make_dev.R ├── modules_fn.R ├── pkg_tools.R ├── reload.R ├── run_dev.R ├── sanity_check.R ├── set_golem_options.R ├── templates.R ├── test_helpers.R ├── use_favicon.R ├── use_files_external.R ├── use_files_external_tools.R ├── use_files_internal.R ├── use_files_internal_tools.R ├── use_files_shared_tools.R ├── use_readme.R ├── use_recommended.R ├── use_utils.R ├── use_utils_tools.R ├── utils.R └── with_opt.R ├── README.Rmd ├── README.md ├── codecov.yml ├── cran-comments.md ├── dev └── config_attachment.yaml ├── inst ├── WORDLIST ├── app │ └── maintenance.html ├── img │ └── golemtemplate.png ├── mantests │ └── build.R ├── rstudio │ ├── addins.dcf │ └── templates │ │ └── project │ │ ├── create_golem.dcf │ │ ├── golem.png │ │ └── shiny.png ├── shinyexample │ ├── .gitignore │ ├── DESCRIPTION │ ├── NAMESPACE │ ├── R │ │ ├── app_config.R │ │ ├── app_server.R │ │ ├── app_ui.R │ │ └── run_app.R │ ├── REMOVEME.Rbuildignore │ ├── dev │ │ ├── 01_start.R │ │ ├── 02_dev.R │ │ ├── 03_deploy.R │ │ └── run_dev.R │ ├── inst │ │ ├── app │ │ │ └── www │ │ │ │ └── favicon.ico │ │ └── golem-config.yml │ └── man │ │ └── run_app.Rd ├── to-do-after-merge-dev.R └── utils │ ├── empty_readme.Rmd │ ├── golem-js.js │ ├── golem_utils_server.R │ ├── golem_utils_ui.R │ ├── sparkle.js │ ├── test-golem-recommended.R │ ├── test-golem_utils_server.R │ ├── test-golem_utils_ui.R │ ├── testfile_template_css.css │ ├── testfile_template_html.html │ ├── testfile_template_js.js │ └── testfile_template_plainfile.txt ├── man ├── add_files.Rd ├── add_module.Rd ├── add_resource_path.Rd ├── addins.Rd ├── amend_golem_config.Rd ├── browser_button.Rd ├── bundle_resources.Rd ├── create_golem.Rd ├── detach_all_attached.Rd ├── disable_autoload.Rd ├── dockerfiles.Rd ├── document_and_reload.Rd ├── favicon.Rd ├── file_creation.Rd ├── fill_desc.Rd ├── get_current_config.Rd ├── get_golem_options.Rd ├── get_sysreqs.Rd ├── golem.Rd ├── golem_js.Rd ├── golem_opts.Rd ├── golem_welcome_page.Rd ├── install_dev_deps.Rd ├── is_golem.Rd ├── is_running.Rd ├── made_dev.Rd ├── maintenance_page.Rd ├── make_dev.Rd ├── module_template.Rd ├── pkg_tools.Rd ├── prod.Rd ├── project_hook.Rd ├── rstudio_deploy.Rd ├── run_dev.Rd ├── sanity_check.Rd ├── template.Rd ├── testhelpers.Rd ├── use_files.Rd ├── use_module_test.Rd ├── use_readme_rmd.Rd ├── use_recommended.Rd ├── utils_files.Rd └── with_golem_options.Rd ├── pkgdown ├── _pkgdown.yml └── extra.scss ├── tests ├── spelling.R ├── testthat.R └── testthat │ ├── Dockerfile.RDS │ ├── _snaps │ ├── after_creation_msg.md │ ├── browser_button.md │ ├── cats.md │ ├── config.md │ ├── use_files_external_tools.md │ ├── use_files_internal_tools.md │ └── use_files_shared_tools.md │ ├── browser_button.test │ ├── dockerfiler_dock_from_renv_socle.RDS │ ├── renv.lock.prod │ ├── setup.R │ ├── test-add_dockerfiles.R │ ├── test-add_dockerfiles_renv.R │ ├── test-add_files.R │ ├── test-add_r_files.R │ ├── test-add_resource_path.R │ ├── test-add_rstudio_files.R │ ├── test-addins.R │ ├── test-after_creation_msg.R │ ├── test-browser_button.R │ ├── test-bundle_resources.R │ ├── test-cats.R │ ├── test-config.R │ ├── test-create_golem.R │ ├── test-desc.R │ ├── test-disable_autoload.R │ ├── test-enable_roxygenize.R │ ├── test-file_endings.R │ ├── test-get_sysreqs.R │ ├── test-globals.R │ ├── test-golem-yaml-get.R │ ├── test-golem-yaml-set.R │ ├── test-golem-yaml-utils.R │ ├── test-golem_welcome_page.R │ ├── test-install_dev_deps.R │ ├── test-is_golem.R │ ├── test-is_running.R │ ├── test-js.R │ ├── test-maintenance_page.R │ ├── test-make_dev.R │ ├── test-modules_fn.R │ ├── test-pkg_tools.R │ ├── test-reload.R │ ├── test-run_dev.R │ ├── test-sanity_check.R │ ├── test-set_golem_options.R │ ├── test-templates.R │ ├── test-test_helpers.R │ ├── test-use_favicon.R │ ├── test-use_files.R │ ├── test-use_files_external_tools.R │ ├── test-use_files_internal_tools.R │ ├── test-use_files_shared_tools.R │ ├── test-use_readme.R │ ├── test-use_recommended.R │ ├── test-use_utils.R │ ├── test-utils.R │ └── test-with_opt.R └── vignettes ├── .gitignore ├── a-getting-started.Rmd ├── b-develop.Rmd ├── c-deploy.Rmd ├── d-js.Rmd ├── e-config.Rmd ├── f-extending_golem.Rmd ├── g-contribute.Rmd ├── golem_cheatsheet_V0.1.jpg ├── golemtemplate.png ├── h-resources.Rmd └── rstudioprojecthook.png /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^codecov\.yml$ 2 | ^\./app\.R$ 3 | ^reference$ 4 | ^docs$ 5 | ^_pkgdown\.yml$ 6 | ^\.travis\.yml$ 7 | ^Dockerfile$ 8 | ^data-raw$ 9 | ^.*\.Rproj$ 10 | ^\.Rproj\.user$ 11 | ^devtools_history\.R$ 12 | ^README\.Rmd$ 13 | ^readme_figures$ 14 | ^LICENSE\.md$ 15 | ^CODE_OF_CONDUCT\.md$ 16 | ^app\.R$ 17 | ^cran-comments\.md$ 18 | ^CRAN-RELEASE$ 19 | ^appveyor\.yml$ 20 | ^CONTRIBUTING\.md$ 21 | ^doc$ 22 | ^Meta$ 23 | ^\.github$ 24 | ^revdep$ 25 | README.html 26 | ^CRAN-SUBMISSION$ 27 | ^dev$ 28 | ^pkgdown$ 29 | ^\.pre-commit-config\.yaml$ 30 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Declare files that will always have CRLF line endings on checkout. 5 | *.Rd text eol=lf 6 | *.R text eol=lf 7 | *.Rmd text eol=lf 8 | *.md text eol=lf 9 | NAMESPACE text eol=lf 10 | DESCRIPTION text eol=lf 11 | 12 | # Denote all files that are truly binary and should not be modified. 13 | *.png binary 14 | *.jpg binary 15 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: ColinFay 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. 16 | 1. ... 17 | 2. ... 18 | 19 | **Expected behavior** 20 | A clear and concise description of what you expected to happen. 21 | 22 | **Screenshots** 23 | If applicable, add screenshots to help explain your problem. 24 | 25 | **session info** 26 | 27 | please insert here the output of `devtools::session_info()` 28 | 29 | **Additional context** 30 | Add any other context about the problem here. 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FR]" 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/todo.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: todo 3 | about: Internal issue template for golem developers 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## User - Validation 11 | 12 | + [ ] First thing to do to validate this as an external user 13 | + [ ] Second thing to do to validate this as an external user 14 | 15 | ## Dev - Tech 16 | 17 | _A paragraph that details what this functionality does and how it will be implemented._ 18 | 19 | + [ ] A sentence that sums up a feature 20 | + [ ] Implementation number 1 21 | + [ ] Implementation number 2 22 | + [ ] Technical validation 23 | + [ ] A sentence that sums up a feature 24 | + [ ] Implementation number 1 25 | + [ ] Implementation number 2 26 | + [ ] Technical validation 27 | 28 | ## Estimated time 29 | 30 | 01h00. 31 | 32 | + [ ] Add the estimate as a comment with `/estimate` 33 | + [ ] When I close this issue, `devtools::check()` is 0 0 0 34 | + [ ] When I close the issue, I've written the time spent solving this issue, using `/spent` 35 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master, dev] 6 | pull_request: 7 | branches: [main, master, dev] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macos-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'oldrel-1'} 26 | 27 | env: 28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 29 | R_KEEP_PKG_SOURCE: yes 30 | 31 | steps: 32 | - uses: actions/checkout@v3 33 | 34 | - uses: r-lib/actions/setup-pandoc@v2 35 | 36 | - uses: r-lib/actions/setup-r@v2 37 | with: 38 | r-version: ${{ matrix.config.r }} 39 | http-user-agent: ${{ matrix.config.http-user-agent }} 40 | use-public-rspm: true 41 | 42 | - uses: r-lib/actions/setup-r-dependencies@v2 43 | with: 44 | extra-packages: any::rcmdcheck 45 | needs: check 46 | 47 | - uses: r-lib/actions/check-r-package@v2 48 | with: 49 | upload-snapshots: true 50 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | - master 6 | 7 | name: pkgdown 8 | 9 | jobs: 10 | pkgdown: 11 | runs-on: ubuntu-latest 12 | # Only restrict concurrency for non-PR jobs 13 | concurrency: 14 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 15 | env: 16 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 17 | permissions: 18 | contents: write 19 | steps: 20 | - uses: actions/checkout@v3 21 | 22 | - uses: r-lib/actions/setup-pandoc@v2 23 | 24 | - uses: r-lib/actions/setup-r@v2 25 | with: 26 | use-public-rspm: true 27 | 28 | - uses: r-lib/actions/setup-r-dependencies@v2 29 | with: 30 | extra-packages: any::pkgdown, local::. 31 | needs: website 32 | 33 | - name: Build site 34 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 35 | shell: Rscript {0} 36 | 37 | - name: Deploy to GitHub pages 🚀 38 | if: github.event_name != 'pull_request' 39 | uses: JamesIves/github-pages-deploy-action@v4.4.1 40 | with: 41 | clean: false 42 | branch: gh-pages 43 | folder: docs 44 | -------------------------------------------------------------------------------- /.github/workflows/pr-commands.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | issue_comment: 3 | types: [created] 4 | name: Commands 5 | jobs: 6 | document: 7 | if: startsWith(github.event.comment.body, '/document') 8 | name: document 9 | runs-on: macOS-latest 10 | env: 11 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 12 | steps: 13 | - uses: actions/checkout@v2 14 | - uses: r-lib/actions/pr-fetch@v1 15 | with: 16 | repo-token: ${{ secrets.GITHUB_TOKEN }} 17 | - uses: r-lib/actions/setup-r@v1 18 | - name: Install dependencies 19 | run: Rscript -e 'install.packages(c("remotes", "roxygen2"))' -e 'remotes::install_deps(dependencies = TRUE)' 20 | - name: Document 21 | run: Rscript -e 'roxygen2::roxygenise()' 22 | - name: commit 23 | run: | 24 | git config --local user.email "actions@github.com" 25 | git config --local user.name "GitHub Actions" 26 | git add man/\* NAMESPACE 27 | git commit -m 'Document' 28 | - uses: r-lib/actions/pr-push@v1 29 | with: 30 | repo-token: ${{ secrets.GITHUB_TOKEN }} 31 | style: 32 | if: startsWith(github.event.comment.body, '/style') 33 | name: style 34 | runs-on: macOS-latest 35 | env: 36 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 37 | steps: 38 | - uses: actions/checkout@v2 39 | - uses: r-lib/actions/pr-fetch@v1 40 | with: 41 | repo-token: ${{ secrets.GITHUB_TOKEN }} 42 | - uses: r-lib/actions/setup-r@v1 43 | - name: Install dependencies 44 | run: Rscript -e 'install.packages("styler")' 45 | - name: Style 46 | run: Rscript -e 'styler::style_pkg()' 47 | - name: commit 48 | run: | 49 | git config --local user.email "actions@github.com" 50 | git config --local user.name "GitHub Actions" 51 | git add \*.R 52 | git commit -m 'Style' 53 | - uses: r-lib/actions/pr-push@v1 54 | with: 55 | repo-token: ${{ secrets.GITHUB_TOKEN }} 56 | -------------------------------------------------------------------------------- /.github/workflows/recheck.yml: -------------------------------------------------------------------------------- 1 | on: 2 | workflow_dispatch: 3 | inputs: 4 | which: 5 | type: choice 6 | description: Which dependents to check 7 | options: 8 | - strong 9 | - most 10 | 11 | name: Reverse dependency check 12 | 13 | jobs: 14 | revdep_check: 15 | name: Reverse check ${{ inputs.which }} dependents 16 | uses: r-devel/recheck/.github/workflows/recheck.yml@v1 17 | with: 18 | which: ${{ inputs.which }} -------------------------------------------------------------------------------- /.github/workflows/render-rmarkdown-and-bump-version.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | 4 | # Controls when the action will run: for now dev and master 5 | on: 6 | push: 7 | branches: [main, master, dev,test-for-gh] 8 | 9 | name: render-rmarkdown 10 | 11 | jobs: 12 | render-rmarkdown: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | steps: 17 | # Checks-out golem repo so the job can access it 18 | - name: Checkout repo 19 | uses: actions/checkout@v3 20 | with: 21 | fetch-depth: 0 22 | - uses: r-lib/actions/setup-pandoc@v2 23 | - uses: r-lib/actions/setup-r@v2 24 | with: 25 | use-public-rspm: true 26 | 27 | # install linux packages 28 | - name: install linux packages 29 | run: sudo apt-get install -y libgit2-dev 30 | # install CRAN packages used inside README.Rmd 31 | - name: install required packages 32 | run: Rscript -e 'install.packages("remotes");remotes::install_cran(c("rmarkdown", "covr", "gert", "knitr", "devtools", "desc"), repos = "https://packagemanager.posit.co/cran/__linux__/jammy/latest")' 33 | 34 | - uses: r-lib/actions/setup-r-dependencies@v2 35 | with: 36 | extra-packages: any::rcmdcheck 37 | needs: check 38 | 39 | # Render READEME.md using rmarkdown 40 | - name: render README 41 | run: Rscript -e 'rmarkdown::render("README.Rmd", output_format = "md_document")' 42 | - name: Commit Results 43 | run: | 44 | git config --local user.name "$GITHUB_ACTOR" 45 | git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" 46 | git add README.md DESCRIPTION 47 | git commit -m "Re-build README.md" || echo "No changes to commit" 48 | git push origin || echo "No changes to commit" 49 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master, '*coverage*'] 6 | pull_request: 7 | 8 | name: test-coverage.yaml 9 | 10 | permissions: read-all 11 | 12 | jobs: 13 | test-coverage: 14 | runs-on: ubuntu-latest 15 | env: 16 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - uses: r-lib/actions/setup-r@v2 22 | with: 23 | use-public-rspm: true 24 | 25 | - uses: r-lib/actions/setup-r-dependencies@v2 26 | with: 27 | extra-packages: any::covr, any::xml2 28 | needs: coverage 29 | 30 | - name: Test coverage 31 | run: | 32 | cov <- covr::package_coverage( 33 | quiet = FALSE, 34 | clean = FALSE, 35 | install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") 36 | ) 37 | print(cov) 38 | covr::to_cobertura(cov) 39 | shell: Rscript {0} 40 | 41 | - uses: codecov/codecov-action@v5 42 | with: 43 | # Fail if error if not on PR, or if on PR and token is given 44 | fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }} 45 | files: ./cobertura.xml 46 | plugins: noop 47 | disable_search: true 48 | token: ${{ secrets.CODECOV_TOKEN }} 49 | 50 | - name: Show testthat output 51 | if: always() 52 | run: | 53 | ## -------------------------------------------------------------------- 54 | find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true 55 | shell: bash 56 | 57 | - name: Upload test results 58 | if: failure() 59 | uses: actions/upload-artifact@v4 60 | with: 61 | name: coverage-test-failures 62 | path: ${{ runner.temp }}/package 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | inst/doc 2 | docs 3 | inst/rstudio/.DS_Store 4 | **/.DS_Store 5 | *.DS_Store 6 | .Rproj.user 7 | .Rhistory 8 | .RData 9 | doc 10 | Meta 11 | revdep/ 12 | README.html 13 | *.Rproj 14 | /doc/ 15 | /Meta/ 16 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: local 3 | hooks: 4 | # https://github.com/posit-dev/air 5 | - id: air 6 | name: Format R code with air 7 | entry: air format . 8 | language: system 9 | files: \.R$ 10 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (http://contributor-covenant.org), version 1.0.0, available at 25 | http://contributor-covenant.org/version/1/0/0/ 26 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | First of all, thank you for taking time to contribute to `{golem}`! 4 | 5 | ### What you can help with 6 | 7 | There are several ways to contribute to the package: 8 | 9 | 1. Spot typos and/or mistakes in the documentations 10 | 11 | 1. Feature requests or Bug Report 12 | 13 | 1. Contribute the code-base with new features or with bug fixes 14 | 15 | ### How to contribute 16 | 17 | 1. For typos, please open an issue or a Pull request with your change. 18 | 19 | For a simple typo, you can PR into the repo without opening an issue first. 20 | You can also only report the typo without doing a PR. 21 | 22 | 2. For a new feature or bug report, start by opening an issue on this repo. 23 | 24 | You're welcome to fix the bug or implement the feature, but __please don't PR in the repo with features or bugs correction without opening an issue first so that we can discuss the feature / confirm the bug.__ 25 | 26 | ### Making change into `{golem}` 27 | 28 | 1. Fork the repo on your profile. 29 | 30 | 2. `git clone` your repo on your machine. 31 | 32 | ``` 33 | git clone https://github.com/YOURNAME/golem.git 34 | ``` 35 | 36 | 3. Work on the `dev` branch. 37 | 38 | ``` 39 | git branch dev 40 | ``` 41 | 42 | Or use the Git panel from RStudio 43 | 44 | 4. Make the changes locally. 45 | 46 | 5. Be sure to have a `devtools::check()` that return 0 errors, 0 warnings and 0 mistakes 47 | 48 | ```r 49 | devtools::check() 50 | ``` 51 | 52 | If ever you have some errors, please specify it in your commit message / PR comment 53 | 54 | 6. PR the change __into golem dev branch__, not straight to master 55 | 56 | 7. In your PR message, please add the reference of the issue, and the content to be used in NEWS.md. Changes can be : `## New Functions`, `## New features`, `## Breaking changes`, `## Bug fix`, `## Bug fix`, `## Internal changes` 57 | 58 | See https://github.com/ThinkR-open/golem/pull/149 for an example 59 | 60 | ### Styling 61 | 62 | Please style the files according to `grkstyle::grk_style_transformer()` 63 | 64 | ```{r} 65 | # If you work in RStudio 66 | options(styler.addins_style_transformer = "grkstyle::grk_style_transformer()") 67 | 68 | # If you work in VSCode 69 | options(languageserver.formatting_style = function(options) { 70 | grkstyle::grk_style_transformer() 71 | }) 72 | ``` -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 0.5.0 2 | Date: 2024-08-19 06:06:47 UTC 3 | SHA: 5fba0b374253e89e40a45fab6c5c1186be25e8bb 4 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: golem 2 | Title: A Framework for Robust Shiny Applications 3 | Version: 0.5.1.9012 4 | Authors@R: c( 5 | person("Colin", "Fay", , "contact@colinfay.me", role = c("cre", "aut"), 6 | comment = c(ORCID = "0000-0001-7343-1846")), 7 | person("Vincent", "Guyader", , "vincent@thinkr.fr", role = "aut", 8 | comment = c(ORCID = "0000-0003-0671-9270", "previous maintainer")), 9 | person("Sébastien", "Rochette", , "sebastien@thinkr.fr", role = "aut", 10 | comment = c(ORCID = "0000-0002-1565-9313")), 11 | person("Cervan", "Girard", , "cervan@thinkr.fr", role = "aut", 12 | comment = c(ORCID = "0000-0002-4816-4624")), 13 | person("Novica", "Nakov", , "nnovica@gmail.com", role = "ctb"), 14 | person("David", "Granjon", , "dgranjon@ymail.com", role = "ctb"), 15 | person("Arthur", "Bréant", , "arthur@thinkr.fr", role = "ctb"), 16 | person("Antoine", "Languillaume", , "antoine@thinkr.fr", role = "ctb"), 17 | person("Ilya", "Zarubin", , "zarubin@wiso.uni-koeln.de", role = "ctb"), 18 | person("ThinkR", role = "cph") 19 | ) 20 | Description: An opinionated framework for building a production-ready 21 | 'Shiny' application. This package contains a series of tools for 22 | building a robust 'Shiny' application from start to finish. 23 | License: MIT + file LICENSE 24 | URL: https://thinkr-open.github.io/golem/, https://github.com/ThinkR-open/golem 25 | BugReports: https://github.com/ThinkR-open/golem/issues 26 | Depends: 27 | R (>= 3.0) 28 | Imports: 29 | attempt (>= 0.3.0), 30 | codetools, 31 | config, 32 | htmltools, 33 | rlang (>= 1.0.0), 34 | shiny (>= 1.5.0), 35 | utils, 36 | yaml 37 | Suggests: 38 | attachment (>= 0.3.2), 39 | callr, 40 | cli (>= 2.0.0), 41 | covr, 42 | crayon, 43 | desc, 44 | devtools, 45 | dockerfiler (>= 0.2.0), 46 | fs, 47 | httpuv, 48 | knitr, 49 | mockery, 50 | pkgbuild, 51 | pkgdown, 52 | pkgload (>= 1.3.0), 53 | processx, 54 | purrr, 55 | rcmdcheck, 56 | remotes, 57 | renv, 58 | rmarkdown, 59 | roxygen2, 60 | rsconnect, 61 | rstudioapi, 62 | sass, 63 | spelling, 64 | stringr, 65 | testthat (>= 3.0.0), 66 | tools, 67 | usethis (>= 1.6.0), 68 | withr 69 | VignetteBuilder: 70 | knitr 71 | Config/testthat/edition: 3 72 | Encoding: UTF-8 73 | Language: en-US 74 | Roxygen: list(markdown = TRUE) 75 | RoxygenNote: 7.3.2 76 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2019 2 | COPYRIGHT HOLDER: ThinkR 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2019 ThinkR 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /R/add_resource_path.R: -------------------------------------------------------------------------------- 1 | #' Add resource path 2 | #' 3 | #' @inheritParams shiny::addResourcePath 4 | #' @param warn_empty Boolean. Default is `FALSE`. 5 | #' If TRUE display message if directory is empty. 6 | #' 7 | #' @importFrom shiny addResourcePath 8 | #' 9 | #' @export 10 | #' 11 | #' @return Used for side effects. 12 | add_resource_path <- function( 13 | prefix, 14 | directoryPath, 15 | warn_empty = FALSE 16 | ) { 17 | list_f <- length( 18 | list.files( 19 | path = directoryPath 20 | ) 21 | ) == 0 22 | 23 | if (list_f) { 24 | if (warn_empty) { 25 | warning("No resources to add from resource path (directory empty).") 26 | } 27 | } else { 28 | addResourcePath(prefix, directoryPath) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /R/boostrap_base.R: -------------------------------------------------------------------------------- 1 | # For mocking purposes 2 | 3 | curl_get_headers <- function(...) { 4 | curlGetHeaders(...) 5 | } 6 | 7 | utils_download_file <- function(...) { 8 | utils::download.file(...) 9 | } 10 | -------------------------------------------------------------------------------- /R/boostrap_cli.R: -------------------------------------------------------------------------------- 1 | # All the fns here check that {cli} is installed 2 | # before doing anything. 3 | check_cli_installed <- function(reason = "to have attractive command line interfaces with {golem}.\nYou can install all {golem} dev dependencies with `golem::install_dev_deps()`.") { 4 | rlang::check_installed( 5 | "cli", 6 | version = "2.0.0", 7 | reason = reason 8 | ) 9 | } 10 | 11 | cli_cat_bullet <- function(...) { 12 | check_cli_installed() 13 | do_if_unquiet({ 14 | cli::cat_bullet(...) 15 | }) 16 | } 17 | 18 | 19 | cli_cat_line <- function(...) { 20 | check_cli_installed() 21 | 22 | do_if_unquiet({ 23 | cli::cat_line(...) 24 | }) 25 | } 26 | 27 | cli_cat_rule <- function(...) { 28 | check_cli_installed() 29 | 30 | do_if_unquiet({ 31 | cli::cat_rule( 32 | ... 33 | ) 34 | }) 35 | } 36 | 37 | cli_cli_alert_info <- function(...) { 38 | check_cli_installed() 39 | 40 | do_if_unquiet({ 41 | cli::cli_alert_info( 42 | ... 43 | ) 44 | }) 45 | } 46 | 47 | cli_cli_abort <- function(message) { 48 | if (rlang::is_installed("cli")) { 49 | cli::cli_abort(message = message, call = NULL) 50 | } else { 51 | stop(message) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /R/boostrap_crayon.R: -------------------------------------------------------------------------------- 1 | # All the fns here check that {cli} is installed 2 | # before doing anything. 3 | check_crayon_installed <- function(reason = "to have attractive command line interfaces with {golem}.\nYou can install all {golem} dev dependencies with `golem::install_dev_deps()`.") { 4 | rlang::check_installed( 5 | "crayon", 6 | reason = reason 7 | ) 8 | } 9 | 10 | 11 | # from usethis https://github.com/r-lib/usethis/ 12 | crayon_darkgrey <- function(x) { 13 | check_crayon_installed() 14 | x <- crayon::make_style("darkgrey")(x) 15 | } 16 | -------------------------------------------------------------------------------- /R/boostrap_fs.R: -------------------------------------------------------------------------------- 1 | # All the fns here check that {fs} is installed 2 | # before doing anything. 3 | check_fs_installed <- function() { 4 | rlang::check_installed( 5 | "fs", 6 | reason = "for file & directory manipulation.\nYou can install all {golem} dev dependencies with `golem::install_dev_deps()`." 7 | ) 8 | } 9 | 10 | fs_dir_exists <- function(path) { 11 | check_fs_installed() 12 | fs::dir_exists(path) 13 | } 14 | 15 | fs_dir_create <- function( 16 | path, 17 | ..., 18 | mode = "u=rwx,go=rx", 19 | recurse = TRUE, 20 | recursive 21 | ) { 22 | check_fs_installed() 23 | fs::dir_create( 24 | path, 25 | ..., 26 | mode = mode, 27 | recurse = recurse, 28 | recursive = recursive 29 | ) 30 | } 31 | 32 | fs_file_create <- function(where) { 33 | check_fs_installed() 34 | fs::file_create(where) 35 | } 36 | 37 | fs_dir_delete <- function(path) { 38 | check_fs_installed() 39 | fs::dir_delete(path) 40 | } 41 | 42 | fs_file_delete <- function(path) { 43 | check_fs_installed() 44 | fs::file_delete(path) 45 | } 46 | 47 | fs_file_exists <- function(path) { 48 | check_fs_installed() 49 | fs::file_exists(path) 50 | } 51 | 52 | fs_path_abs <- function(path) { 53 | check_fs_installed() 54 | fs::path_abs(path) 55 | } 56 | 57 | fs_path <- function(..., ext = "") { 58 | check_fs_installed() 59 | fs::path(..., ext = ext) 60 | } 61 | 62 | fs_file_copy <- function( 63 | path, 64 | new_path, 65 | overwrite = FALSE 66 | ) { 67 | check_fs_installed() 68 | fs::file_copy( 69 | path = path, 70 | new_path = new_path, 71 | overwrite 72 | ) 73 | } 74 | 75 | fs_dir_copy <- function( 76 | path, 77 | new_path, 78 | overwrite = FALSE 79 | ) { 80 | check_fs_installed() 81 | fs::dir_copy( 82 | path, 83 | new_path, 84 | overwrite 85 | ) 86 | } 87 | -------------------------------------------------------------------------------- /R/bootstrap_attachment.R: -------------------------------------------------------------------------------- 1 | # All the fns here check that {attachment} is installed 2 | # before doing anything. 3 | check_attachment_installed <- function() { 4 | rlang::check_installed( 5 | "attachment", 6 | version = "0.3.2", 7 | reason = "to build a Dockerfile." 8 | ) 9 | } 10 | 11 | attachment_create_renv_for_prod <- function( 12 | path = ".", 13 | output = "renv.lock.prod", 14 | dev_pkg = "remotes", 15 | check_if_suggests_is_installed = FALSE, 16 | document = FALSE, 17 | ... 18 | ) { 19 | check_attachment_installed() 20 | attachment::create_renv_for_prod( 21 | path = path, 22 | output = output, 23 | dev_pkg = dev_pkg, 24 | document = document, 25 | check_if_suggests_is_installed = check_if_suggests_is_installed, 26 | ... 27 | ) 28 | } 29 | -------------------------------------------------------------------------------- /R/bootstrap_desc.R: -------------------------------------------------------------------------------- 1 | # All the fns here check that {desc} is installed 2 | # before doing anything. 3 | check_desc_installed <- function() { 4 | rlang::check_installed( 5 | "desc", 6 | reason = "to fill DESCRIPTION." 7 | ) 8 | } 9 | 10 | desc_description <- function(file) { 11 | check_desc_installed() 12 | desc::description$new( 13 | file = file 14 | ) 15 | } 16 | 17 | desc_get <- function(keys) { 18 | check_desc_installed() 19 | desc::desc_get(keys) 20 | } 21 | 22 | desc_get_version <- function() { 23 | check_desc_installed() 24 | desc::desc_get_version() 25 | } 26 | 27 | desc_get_deps <- function(file = NULL) { 28 | check_desc_installed() 29 | desc::desc_get_deps(file) 30 | } 31 | 32 | desc_get_field <- function(key) { 33 | check_desc_installed() 34 | desc::desc_get_field(key) 35 | } 36 | 37 | desc_get_author <- function() { 38 | check_desc_installed() 39 | desc::desc_get_author() 40 | } 41 | -------------------------------------------------------------------------------- /R/bootstrap_dockerfiler.R: -------------------------------------------------------------------------------- 1 | # All the fns here check that {dockerfiler} is installed 2 | # before doing anything. 3 | check_dockerfiler_installed <- function() { 4 | rlang::check_installed( 5 | "dockerfiler", 6 | version = "0.2.0", 7 | reason = "to build a Dockerfile." 8 | ) 9 | } 10 | 11 | dockerfiler_dock_from_renv <- function( 12 | lockfile = "renv.lock", 13 | distro = "focal", 14 | FROM = "rocker/r-base", 15 | AS = NULL, 16 | sysreqs = TRUE, 17 | repos = c(CRAN = "https://cran.rstudio.com/"), 18 | expand = FALSE, 19 | extra_sysreqs = NULL 20 | ) { 21 | check_dockerfiler_installed() 22 | dockerfiler::dock_from_renv( 23 | lockfile = lockfile, 24 | distro = distro, 25 | FROM = FROM, 26 | AS = AS, 27 | sysreqs = sysreqs, 28 | repos = repos, 29 | expand = expand, 30 | extra_sysreqs = extra_sysreqs 31 | ) 32 | } 33 | 34 | dockerfiler_dock_from_desc <- function( 35 | path = "DESCRIPTION", 36 | FROM = paste0( 37 | "rocker/r-ver:", 38 | R.Version()$major, 39 | ".", 40 | R.Version()$minor 41 | ), 42 | AS = NULL, 43 | sysreqs = TRUE, 44 | repos = c(CRAN = "https://cran.rstudio.com/"), 45 | expand = FALSE, 46 | update_tar_gz = TRUE, 47 | build_from_source = TRUE, 48 | extra_sysreqs = NULL 49 | ) { 50 | check_dockerfiler_installed() 51 | dockerfiler::dock_from_desc( 52 | path = path, 53 | FROM = FROM, 54 | AS = AS, 55 | sysreqs = sysreqs, 56 | repos = repos, 57 | expand = expand, 58 | update_tar_gz = update_tar_gz, 59 | build_from_source = build_from_source, 60 | extra_sysreqs = extra_sysreqs 61 | ) 62 | } 63 | 64 | 65 | dockerfiler_Dockerfile <- function() { 66 | check_dockerfiler_installed() 67 | dockerfiler::Dockerfile 68 | } 69 | -------------------------------------------------------------------------------- /R/bootstrap_pkgload.R: -------------------------------------------------------------------------------- 1 | # All the fns here check that {pkgload} is installed 2 | # before doing anything. 3 | check_pkgload_installed <- function() { 4 | rlang::check_installed( 5 | "pkgload", 6 | reason = "to load the package.", 7 | version = "1.3.0" 8 | ) 9 | } 10 | 11 | pkgload_load_all <- function( 12 | path = ".", 13 | reset = TRUE, 14 | compile = NA, 15 | attach = TRUE, 16 | export_all = TRUE, 17 | export_imports = export_all, 18 | helpers = TRUE, 19 | attach_testthat = uses_testthat(path), 20 | quiet = NULL, 21 | recompile = FALSE, 22 | warn_conflicts = TRUE 23 | ) { 24 | check_roxygen2_installed() 25 | check_pkgload_installed() 26 | 27 | uses_testthat <- getFromNamespace("uses_testthat", "pkgload") 28 | pkgload::load_all( 29 | path = path, 30 | reset = reset, 31 | compile = compile, 32 | attach = attach, 33 | export_all = export_all, 34 | export_imports = export_imports, 35 | helpers = helpers, 36 | attach_testthat = attach_testthat, 37 | quiet = quiet, 38 | recompile = recompile, 39 | warn_conflicts = warn_conflicts 40 | ) 41 | } 42 | -------------------------------------------------------------------------------- /R/bootstrap_rlang.R: -------------------------------------------------------------------------------- 1 | # For mocking purposes 2 | rlang_is_interactive <- rlang::is_interactive 3 | 4 | rlang_is_installed <- rlang::is_installed 5 | -------------------------------------------------------------------------------- /R/bootstrap_roxygen2.R: -------------------------------------------------------------------------------- 1 | # All the fns here check that {roxygen2} is installed 2 | # before doing anything. 3 | check_roxygen2_installed <- function() { 4 | rlang::check_installed( 5 | "roxygen2", 6 | reason = "to document the package." 7 | ) 8 | } 9 | 10 | roxygen2_roxygenise <- function( 11 | package.dir = ".", 12 | roclets = NULL, 13 | load_code = NULL, 14 | clean = FALSE 15 | ) { 16 | check_roxygen2_installed() 17 | roxygen2::roxygenise( 18 | package.dir = package.dir, 19 | roclets = roclets, 20 | load_code = load_code, 21 | clean = clean 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /R/bootstrap_rstudio_api.R: -------------------------------------------------------------------------------- 1 | check_rstudioapi_installed <- function(reason = "to manipulate RStudio files.") { 2 | rlang::check_installed( 3 | "rstudioapi", 4 | reason = reason 5 | ) 6 | } 7 | 8 | 9 | rstudioapi_navigateToFile <- function(output) { 10 | # Don't suggest to install 11 | if (rlang::is_installed("rstudioapi")) { 12 | if ( 13 | rstudioapi::isAvailable() & 14 | rstudioapi::hasFun("navigateToFile") 15 | ) { 16 | rstudioapi::navigateToFile(output) 17 | } else { 18 | try(file.edit(output)) 19 | } 20 | } else { 21 | try(file.edit(output)) 22 | } 23 | } 24 | 25 | rstudioapi_hasFun <- function(fun) { 26 | # Default to FALSE so that it's FALSE 27 | # If package is not installed 28 | hasFun <- FALSE 29 | if (rlang::is_installed("rstudioapi")) { 30 | hasFun <- rstudioapi::hasFun(fun) 31 | } 32 | hasFun 33 | } 34 | 35 | rstudioapi_getSourceEditorContext <- function() { 36 | check_rstudioapi_installed() 37 | rstudioapi::getSourceEditorContext() 38 | } 39 | 40 | rstudioapi_modifyRange <- function( 41 | location = NULL, 42 | text = NULL, 43 | id = NULL 44 | ) { 45 | check_rstudioapi_installed() 46 | rstudioapi::modifyRange( 47 | location = location, 48 | text = text, 49 | id = id 50 | ) 51 | } 52 | -------------------------------------------------------------------------------- /R/bootstrap_testthat.R: -------------------------------------------------------------------------------- 1 | # All the fns here check that {usethis} is installed 2 | # before doing anything. 3 | check_testthat_installed <- function( 4 | reason = "for testing purposes." 5 | ) { 6 | rlang::check_installed( 7 | "testthat", 8 | version = "3.0.0", 9 | reason = reason 10 | ) 11 | } 12 | 13 | testthat_expect_snapshot <- function(...) { 14 | check_testthat_installed() 15 | testthat::expect_snapshot(...) 16 | } 17 | -------------------------------------------------------------------------------- /R/bootstrap_usethis.R: -------------------------------------------------------------------------------- 1 | # All the fns here check that {usethis} is installed 2 | # before doing anything. 3 | check_usethis_installed <- function(reason = "for project and file manipulation.") { 4 | rlang::check_installed( 5 | "usethis", 6 | version = "1.6.0", 7 | reason = reason 8 | ) 9 | } 10 | 11 | usethis_use_build_ignore <- function( 12 | files, 13 | escape = TRUE 14 | ) { 15 | check_usethis_installed( 16 | reason = "to ignore files in the build." 17 | ) 18 | usethis::use_build_ignore( 19 | files, 20 | escape 21 | ) 22 | } 23 | usethis_use_package <- function( 24 | package, 25 | type = "Imports", 26 | min_version = NULL 27 | ) { 28 | check_usethis_installed( 29 | reason = "to add dependencies to DESCRIPTION." 30 | ) 31 | usethis::use_package( 32 | package, 33 | type, 34 | min_version 35 | ) 36 | } 37 | 38 | 39 | usethis_proj_set <- function( 40 | path = ".", 41 | force = FALSE 42 | ) { 43 | check_usethis_installed( 44 | reason = "to set project." 45 | ) 46 | usethis::proj_set( 47 | path, 48 | force 49 | ) 50 | } 51 | usethis_use_testthat <- function( 52 | edition = NULL, 53 | parallel = FALSE 54 | ) { 55 | check_usethis_installed( 56 | reason = "to add {testthat} infrastructure." 57 | ) 58 | usethis::use_testthat( 59 | edition, 60 | parallel 61 | ) 62 | } 63 | usethis_use_test <- function( 64 | name = NULL, 65 | open = rlang::is_interactive() 66 | ) { 67 | check_usethis_installed( 68 | reason = "to add tests." 69 | ) 70 | usethis::use_test( 71 | name, 72 | open 73 | ) 74 | } 75 | 76 | usethis_use_spell_check <- function( 77 | vignettes = TRUE, 78 | lang = "en-US", 79 | error = FALSE 80 | ) { 81 | check_usethis_installed( 82 | reason = "to add spellcheck." 83 | ) 84 | usethis::use_spell_check( 85 | vignettes, 86 | lang, 87 | error 88 | ) 89 | } 90 | 91 | usethis_use_readme_rmd <- function( 92 | open = rlang::is_interactive() 93 | ) { 94 | check_usethis_installed( 95 | reason = "to create a readme." 96 | ) 97 | usethis::use_readme_rmd( 98 | open = open 99 | ) 100 | } 101 | -------------------------------------------------------------------------------- /R/browser_button.R: -------------------------------------------------------------------------------- 1 | #' Insert an hidden browser button 2 | #' 3 | #' See \url{https://rtask.thinkr.fr/a-little-trick-for-debugging-shiny/} for more context. 4 | #' 5 | #' @return Used for side effects. 6 | #' Prints the code to the console. 7 | #' @export 8 | #' 9 | 10 | browser_button <- function() { 11 | cli_cat_rule("To be copied in your UI") 12 | cli_cat_line(crayon_darkgrey('actionButton("browser", "browser"),')) 13 | cli_cat_line(crayon_darkgrey('tags$script("$(\'#browser\').hide();")')) 14 | cli_cat_line() 15 | cli_cat_rule("To be copied in your server") 16 | cli_cat_line(crayon_darkgrey("observeEvent(input$browser,{")) 17 | cli_cat_line(crayon_darkgrey(" browser()")) 18 | cli_cat_line(crayon_darkgrey("})")) 19 | cli_cat_line() 20 | cli_cat_line("By default, this button will be hidden.") 21 | cli_cat_line("To show it, open your web browser JavaScript console") 22 | cli_cat_line("And run $('#browser').show();") 23 | } 24 | -------------------------------------------------------------------------------- /R/cats.R: -------------------------------------------------------------------------------- 1 | cat_green_tick <- function(...) { 2 | do_if_unquiet({ 3 | cli_cat_bullet( 4 | ..., 5 | bullet = "tick", 6 | bullet_col = "green" 7 | ) 8 | }) 9 | } 10 | 11 | cat_red_bullet <- function(...) { 12 | do_if_unquiet({ 13 | cli_cat_bullet( 14 | ..., 15 | bullet = "bullet", 16 | bullet_col = "red" 17 | ) 18 | }) 19 | } 20 | 21 | cat_info <- function(...) { 22 | do_if_unquiet({ 23 | cli_cat_bullet( 24 | ..., 25 | bullet = "arrow_right", 26 | bullet_col = "grey" 27 | ) 28 | }) 29 | } 30 | 31 | 32 | cat_exists <- function(where) { 33 | do_if_unquiet({ 34 | cat_red_bullet( 35 | sprintf( 36 | "[Skipped] %s already exists.", 37 | basename(where) 38 | ) 39 | ) 40 | cat_info( 41 | sprintf( 42 | "If you want replace it, remove the %s file first.", 43 | basename(where) 44 | ) 45 | ) 46 | }) 47 | } 48 | 49 | cat_dir_necessary <- function() { 50 | do_if_unquiet({ 51 | cat_red_bullet( 52 | "File not added (needs a valid directory)" 53 | ) 54 | }) 55 | } 56 | 57 | cat_start_download <- function() { 58 | do_if_unquiet({ 59 | cli_cat_line("") 60 | cli_cat_line("Initiating file download") 61 | }) 62 | } 63 | 64 | cat_downloaded <- function( 65 | where, 66 | file = "File" 67 | ) { 68 | do_if_unquiet({ 69 | cat_green_tick( 70 | sprintf( 71 | "%s downloaded at %s", 72 | file, 73 | where 74 | ) 75 | ) 76 | }) 77 | } 78 | 79 | cat_start_copy <- function() { 80 | do_if_unquiet({ 81 | cli_cat_line("") 82 | cli_cat_line("Copying file") 83 | }) 84 | } 85 | 86 | cat_copied <- function( 87 | where, 88 | file = "File" 89 | ) { 90 | do_if_unquiet({ 91 | cat_green_tick( 92 | sprintf( 93 | "%s copied to %s", 94 | file, 95 | where 96 | ) 97 | ) 98 | }) 99 | } 100 | 101 | cat_created <- function( 102 | where, 103 | file = "File" 104 | ) { 105 | do_if_unquiet({ 106 | cat_green_tick( 107 | sprintf( 108 | "%s created at %s", 109 | file, 110 | where 111 | ) 112 | ) 113 | }) 114 | } 115 | 116 | # File made dance 117 | 118 | cat_automatically_linked <- function() { 119 | do_if_unquiet({ 120 | cat_green_tick( 121 | "File automatically linked in `golem_add_external_resources()`." 122 | ) 123 | }) 124 | } 125 | -------------------------------------------------------------------------------- /R/disable_autoload.R: -------------------------------------------------------------------------------- 1 | #' Disabling Shiny Autoload of R Scripts 2 | #' 3 | #' @inheritParams add_module 4 | #' 5 | #' @export 6 | #' 7 | #' @examples 8 | #' if (interactive()) { 9 | #' disable_autoload() 10 | #' } 11 | #' @return The path to the file, invisibly. 12 | disable_autoload <- function( 13 | golem_wd = get_golem_wd(), 14 | pkg 15 | ) { 16 | signal_arg_is_deprecated( 17 | pkg, 18 | fun = as.character(sys.call()[[1]]), 19 | "pkg" 20 | ) 21 | fls <- fs_path( 22 | golem_wd, 23 | "R", 24 | "_disable_autoload.R" 25 | ) 26 | if (fs_file_exists(fls)) { 27 | cat_red_bullet( 28 | "_disable_autoload.R already exists, skipping its creation." 29 | ) 30 | } else { 31 | cli_cat_rule("Creating _disable_autoload.R") 32 | write( 33 | "# Disabling shiny autoload\n\n# See ?shiny::loadSupport for more information", 34 | fls 35 | ) 36 | cat_green_tick("Created") 37 | } 38 | return( 39 | invisible( 40 | fls 41 | ) 42 | ) 43 | } 44 | -------------------------------------------------------------------------------- /R/enable_roxygenize.R: -------------------------------------------------------------------------------- 1 | #' Enable documentation generation using roxygen2 2 | #' 3 | #' @param path to to Rproj file 4 | #' @noRd 5 | #' 6 | enable_roxygenize <- function( 7 | path = list.files( 8 | path = ".", 9 | pattern = "Rproj$", 10 | full.names = TRUE 11 | )[1] 12 | ) { 13 | cli_cat_bullet( 14 | sprintf("Reading %s content ", basename(path)), 15 | bullet = "info", 16 | bullet_col = "green" 17 | ) 18 | source <- yaml::read_yaml(file = path) 19 | cli_cat_bullet( 20 | "Enable roxygen2", 21 | bullet = "info", 22 | bullet_col = "green" 23 | ) 24 | source[["PackageRoxygenize"]] <- "rd,collate,namespace" 25 | yaml::write_yaml(x = source, file = path) 26 | 27 | cat_green_tick("Done") 28 | } 29 | -------------------------------------------------------------------------------- /R/get_sysreqs.R: -------------------------------------------------------------------------------- 1 | # Now in `{dockerfiler}` 2 | 3 | #' Get system requirements (Deprecated) 4 | #' 5 | #' This function is now deprecated, and was moved to 6 | #' `{dockerfiler}`. 7 | #' 8 | #' @param packages character vector. Packages names. 9 | #' @param batch_n numeric. Number of simultaneous packages to ask. 10 | #' @param quiet Boolean. If `TRUE` the function is quiet. 11 | #' 12 | #' 13 | #' @export 14 | #' 15 | #' @return A vector of system requirements. 16 | get_sysreqs <- function( 17 | packages, 18 | quiet = TRUE, 19 | batch_n = 30 20 | ) { 21 | .Deprecated( 22 | "dockerfiler::get_sysreqs", 23 | msg = "get_sysreqs() is deprecated and has been moved to {dockerfiler}." 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /R/globals.R: -------------------------------------------------------------------------------- 1 | .golem_globals <- new.env() 2 | .golem_globals$running <- FALSE 3 | 4 | set_golem_global <- function(name, val) { 5 | .golem_globals[[name]] <- val 6 | } 7 | -------------------------------------------------------------------------------- /R/golem-package.R: -------------------------------------------------------------------------------- 1 | #' A package for building Shiny App 2 | #' 3 | #' Read more about building big shiny apps at [https://engineering-shiny.org/](https://engineering-shiny.org/). 4 | #' 5 | #' @docType package 6 | #' @name golem 7 | "_PACKAGE" 8 | -------------------------------------------------------------------------------- /R/golem-yaml-get.R: -------------------------------------------------------------------------------- 1 | #' @importFrom config get 2 | get_golem_things <- function( 3 | value, 4 | config = Sys.getenv( 5 | "GOLEM_CONFIG_ACTIVE", 6 | Sys.getenv( 7 | "R_CONFIG_ACTIVE", 8 | "default" 9 | ) 10 | ), 11 | use_parent = TRUE, 12 | golem_wd, 13 | fall_back_fun = list, 14 | path 15 | ) { 16 | signal_arg_is_deprecated( 17 | path, 18 | fun = as.character(sys.call()[[1]]) 19 | ) 20 | conf_path <- get_current_config( 21 | golem_wd 22 | ) 23 | stop_if( 24 | conf_path, 25 | is.null, 26 | "Unable to retrieve golem config file." 27 | ) 28 | res <- config::get( 29 | value = value, 30 | config = config, 31 | file = conf_path, 32 | use_parent = TRUE 33 | ) 34 | if (is.null(res)) { 35 | res <- fall_back_fun(golem_wd) 36 | } 37 | return(res) 38 | } 39 | 40 | #' @export 41 | #' @rdname golem_opts 42 | get_golem_wd <- function( 43 | use_parent = TRUE, 44 | golem_wd = golem::pkg_path(), 45 | pkg 46 | ) { 47 | signal_arg_is_deprecated( 48 | pkg, 49 | fun = as.character(sys.call()[[1]]), 50 | first_arg = "pkg" 51 | ) 52 | 53 | get_golem_things( 54 | value = "golem_wd", 55 | config = "dev", 56 | use_parent = use_parent, 57 | golem_wd = fs_path_abs(golem_wd), 58 | fall_back_fun = golem::pkg_path 59 | ) 60 | } 61 | 62 | #' @export 63 | #' @rdname golem_opts 64 | get_golem_name <- function( 65 | config = Sys.getenv( 66 | "GOLEM_CONFIG_ACTIVE", 67 | Sys.getenv( 68 | "R_CONFIG_ACTIVE", 69 | "default" 70 | ) 71 | ), 72 | use_parent = TRUE, 73 | golem_wd = golem::pkg_path(), 74 | pkg 75 | ) { 76 | signal_arg_is_deprecated( 77 | pkg, 78 | fun = as.character(sys.call()[[1]]), 79 | first_arg = "pkg" 80 | ) 81 | get_golem_things( 82 | value = "golem_name", 83 | config = config, 84 | use_parent = use_parent, 85 | golem_wd = fs_path_abs(golem_wd), 86 | fall_back_fun = golem::pkg_name 87 | ) 88 | } 89 | 90 | #' @export 91 | #' @rdname golem_opts 92 | get_golem_version <- function( 93 | config = Sys.getenv( 94 | "GOLEM_CONFIG_ACTIVE", 95 | Sys.getenv( 96 | "R_CONFIG_ACTIVE", 97 | "default" 98 | ) 99 | ), 100 | use_parent = TRUE, 101 | golem_wd = golem::pkg_path(), 102 | pkg 103 | ) { 104 | signal_arg_is_deprecated( 105 | pkg, 106 | fun = as.character(sys.call()[[1]]), 107 | first_arg = "pkg" 108 | ) 109 | get_golem_things( 110 | value = "golem_version", 111 | config = config, 112 | use_parent = use_parent, 113 | golem_wd = fs_path_abs(golem_wd), 114 | fall_back_fun = golem::pkg_version 115 | ) 116 | } 117 | -------------------------------------------------------------------------------- /R/golem-yaml-utils.R: -------------------------------------------------------------------------------- 1 | # This file contains all the necessary functions 2 | # required to manipualte the golem-config file. 3 | 4 | add_expr_tag <- function(tag) { 5 | attr(tag[[1]], "tag") <- "!expr" 6 | tag 7 | } 8 | 9 | # find and tag expressions in a yaml 10 | # used internally in `amend_golem_config` 11 | # This is an utilitary function to prevent 12 | # the !expr from being lost in translation 13 | # when manipulating the yaml 14 | # 15 | #' @importFrom utils modifyList 16 | find_and_tag_exprs <- function(conf_path) { 17 | conf <- yaml::read_yaml( 18 | conf_path, 19 | eval.expr = FALSE 20 | ) 21 | conf.eval <- yaml::read_yaml( 22 | conf_path, 23 | eval.expr = TRUE 24 | ) 25 | 26 | expr_list <- lapply( 27 | names(conf), 28 | function(x) { 29 | conf[[x]][!conf[[x]] %in% conf.eval[[x]]] 30 | } 31 | ) 32 | 33 | names(expr_list) <- names(conf) 34 | 35 | expr_list <- Filter( 36 | function(x) length(x) > 0, 37 | expr_list 38 | ) 39 | 40 | tagged_exprs <- lapply( 41 | expr_list, 42 | add_expr_tag 43 | ) 44 | 45 | modifyList( 46 | conf, 47 | tagged_exprs 48 | ) 49 | } 50 | 51 | 52 | 53 | #' Amend golem config file 54 | #' 55 | #' @param key key of the value to add in `config` 56 | #' @inheritParams config::get 57 | #' @inheritParams add_module 58 | #' @inheritParams set_golem_options 59 | #' 60 | #' @export 61 | #' @importFrom yaml read_yaml write_yaml 62 | #' @importFrom attempt stop_if 63 | #' 64 | #' @return Used for side effects. 65 | amend_golem_config <- function( 66 | key, 67 | value, 68 | config = "default", 69 | golem_wd = golem::pkg_path(), 70 | talkative = TRUE, 71 | pkg 72 | ) { 73 | signal_arg_is_deprecated( 74 | pkg, 75 | fun = as.character(sys.call()[[1]]), 76 | "pkg" 77 | ) 78 | conf_path <- get_current_config(golem_wd) 79 | 80 | stop_if( 81 | conf_path, 82 | is.null, 83 | "Unable to retrieve golem config file." 84 | ) 85 | 86 | cat_if_talk <- function( 87 | ..., 88 | fun = cat_green_tick 89 | ) { 90 | if (talkative) { 91 | fun(...) 92 | } 93 | } 94 | 95 | cat_if_talk( 96 | sprintf( 97 | "Setting `%s` to %s", 98 | key, 99 | value 100 | ) 101 | ) 102 | 103 | if (key == "golem_wd") { 104 | cat_if_talk( 105 | "You can change golem working directory with set_golem_wd('path/to/wd')", 106 | fun = cli_cat_line 107 | ) 108 | } 109 | 110 | conf <- find_and_tag_exprs(conf_path) 111 | conf[[config]][[key]] <- value 112 | 113 | write_yaml( 114 | conf, 115 | conf_path 116 | ) 117 | 118 | invisible(TRUE) 119 | } 120 | -------------------------------------------------------------------------------- /R/is_golem.R: -------------------------------------------------------------------------------- 1 | #' Is the directory a golem-based app? 2 | #' 3 | #' Trying to guess if `path` is a golem-based app. 4 | #' 5 | #' @param path Path to the directory to check. 6 | #' Defaults to the current working directory. 7 | #' 8 | #' @return A boolean, `TRUE` if the directory is a golem-based app, `FALSE` else. 9 | #' 10 | #' @export 11 | #' 12 | #' @examples 13 | #' is_golem() 14 | is_golem <- function(path = getwd()) { 15 | files_from_shiny_example <- grep( 16 | "^(?!REMOVEME).*", 17 | list.files( 18 | system.file("shinyexample", package = "golem"), 19 | recursive = TRUE 20 | ), 21 | perl = TRUE, 22 | value = TRUE 23 | ) 24 | files_from_shiny_example <- grep( 25 | "favicon.ico", 26 | files_from_shiny_example, 27 | perl = TRUE, 28 | value = TRUE, 29 | invert = TRUE 30 | ) 31 | 32 | all( 33 | files_from_shiny_example %in% list.files(path, recursive = TRUE) 34 | ) 35 | } 36 | -------------------------------------------------------------------------------- /R/is_running.R: -------------------------------------------------------------------------------- 1 | #' Is the running app a golem app? 2 | #' 3 | #' Note that this will return `TRUE` only if the application 4 | #' has been launched with `with_golem_options()` 5 | #' 6 | #' @return TRUE if the running app is a `{golem}` based app, 7 | #' FALSE otherwise. 8 | #' @export 9 | #' 10 | #' @examples 11 | #' is_running() 12 | is_running <- function() { 13 | .golem_globals$running 14 | } 15 | -------------------------------------------------------------------------------- /R/maintenance_page.R: -------------------------------------------------------------------------------- 1 | #' maintenance_page 2 | #' 3 | #' A default html page for maintenance mode 4 | #' 5 | #' @importFrom shiny htmlTemplate 6 | #' 7 | #' @return an html_document 8 | #' @details see the vignette \code{vignette("f_extending_golem", package = "golem")} for details. 9 | #' @export 10 | maintenance_page <- function() { 11 | shiny::htmlTemplate( 12 | filename = system.file( 13 | "app", 14 | "maintenance.html", 15 | package = "golem" 16 | ) 17 | ) 18 | } 19 | -------------------------------------------------------------------------------- /R/make_dev.R: -------------------------------------------------------------------------------- 1 | #' Make a function dependent to dev mode 2 | #' 3 | #' The function returned will be run only if `golem::app_dev()` 4 | #' returns TRUE. 5 | #' 6 | #' @param fun A function 7 | #' 8 | #' @export 9 | #' 10 | #' @return Used for side-effects 11 | make_dev <- function(fun) { 12 | function(...) { 13 | if (golem::app_dev()) { 14 | fun(...) 15 | } 16 | } 17 | } 18 | 19 | `%||%` <- function(x, y) { 20 | if (is.null(x)) y else x 21 | } 22 | 23 | #' Is the app in dev mode or prod mode? 24 | #' 25 | #' @return `TRUE` or `FALSE` depending on the status of `getOption( "golem.app.prod")` 26 | #' @export 27 | #' 28 | #' @rdname prod 29 | app_prod <- function() { 30 | getOption("golem.app.prod") %||% FALSE 31 | } 32 | 33 | # Well, this one does the opposite 34 | #' @rdname prod 35 | #' @export 36 | app_dev <- function() { 37 | !golem::app_prod() 38 | } 39 | 40 | #' Functions already made dev dependent 41 | #' 42 | #' This functions will be run only if `golem::app_dev()` 43 | #' returns TRUE. 44 | #' @rdname made_dev 45 | #' @inheritParams base::cat 46 | #' @export 47 | #' @return A modified function. 48 | cat_dev <- make_dev(base::cat) 49 | 50 | #' @rdname made_dev 51 | #' @export 52 | #' @inheritParams base::print 53 | print_dev <- make_dev(base::print) 54 | 55 | #' @rdname made_dev 56 | #' @export 57 | #' @inheritParams base::message 58 | message_dev <- make_dev(base::message) 59 | 60 | #' @rdname made_dev 61 | #' @export 62 | #' @inheritParams base::warning 63 | warning_dev <- make_dev(base::warning) 64 | 65 | #' @rdname made_dev 66 | #' @export 67 | #' @inheritParams base::browser 68 | browser_dev <- make_dev(base::browser) 69 | -------------------------------------------------------------------------------- /R/pkg_tools.R: -------------------------------------------------------------------------------- 1 | # Getting the DESCRIPTION file in a data.frame 2 | daf_desc <- function( 3 | golem_wd = get_golem_wd(), 4 | entry, 5 | path 6 | ) { 7 | signal_arg_is_deprecated( 8 | path, 9 | fun = as.character(sys.call()[[1]]) 10 | ) 11 | as.character( 12 | unlist( 13 | unname( 14 | as.data.frame( 15 | read.dcf( 16 | normalizePath( 17 | fs_path(golem_wd, "DESCRIPTION") 18 | ) 19 | ) 20 | )[entry] 21 | ) 22 | ) 23 | ) 24 | } 25 | 26 | #' Package tools 27 | #' 28 | #' These are functions to help you navigate 29 | #' inside your project while developing 30 | #' 31 | #' @param golem_wd Path to use to read the DESCRIPTION 32 | #' @param path Deprecated, use golem_wd instead 33 | #' 34 | #' @export 35 | #' @rdname pkg_tools 36 | #' 37 | #' @return The value of the entry in the DESCRIPTION file 38 | pkg_name <- function( 39 | golem_wd = get_golem_wd(), 40 | path 41 | ) { 42 | signal_arg_is_deprecated( 43 | path, 44 | fun = as.character(sys.call()[[1]]) 45 | ) 46 | daf_desc( 47 | golem_wd, 48 | "Package" 49 | ) 50 | } 51 | #' @export 52 | #' @rdname pkg_tools 53 | pkg_version <- function( 54 | golem_wd = get_golem_wd(), 55 | path 56 | ) { 57 | signal_arg_is_deprecated( 58 | path, 59 | fun = as.character(sys.call()[[1]]) 60 | ) 61 | daf_desc( 62 | golem_wd, 63 | "Version" 64 | ) 65 | } 66 | #' @export 67 | #' @rdname pkg_tools 68 | pkg_path <- function() { 69 | # rlang::check_installed("here") 70 | # here::here() 71 | getwd() 72 | } 73 | -------------------------------------------------------------------------------- /R/run_dev.R: -------------------------------------------------------------------------------- 1 | #' Run the `dev/run_dev.R` file 2 | #' 3 | #' The default `file="dev/run_dev.R"` launches your `{golem}` app with a bunch 4 | #' of useful options. The file content can be customized and `file`-name and 5 | #' path changed as long as the argument combination of `file` and `pkg` are 6 | #' supplied correctly: the `file`-path is a relative path to a `{golem}`-package 7 | #' root `pkg`. An error is thrown if `pkg/file` cannot be found. 8 | #' 9 | #' The function `run_dev()` is typically used to launch a shiny app by sourcing 10 | #' the content of an appropriate `run_dev`-file. Carefully read the content of 11 | #' `dev/run_dev.R` when creating your custom `run_dev`-file. It has already 12 | #' many useful settings including a switch between production/development, 13 | #' reloading the package in a clean `R` environment before running the app etc. 14 | #' 15 | #' @param file String with (relative) file path to a `run_dev.R`-file 16 | #' @param install_required_packages Boolean; if `TRUE` install the packages 17 | #' used in `run_dev.R`-file 18 | #' @param save_all Boolean; if `TRUE` saves all open files before sourcing 19 | #' `file` 20 | #' @inheritParams add_module 21 | #' 22 | #' @export 23 | #' 24 | #' @return pure side-effect function; returns invisibly 25 | run_dev <- function( 26 | file = "dev/run_dev.R", 27 | golem_wd = get_golem_wd(), 28 | save_all = TRUE, 29 | install_required_packages = TRUE, 30 | pkg 31 | ) { 32 | signal_arg_is_deprecated( 33 | pkg, 34 | fun = as.character(sys.call()[[1]]), 35 | "pkg" 36 | ) 37 | if (save_all) { 38 | if ( 39 | rlang::is_installed("rstudioapi") && 40 | rstudioapi::isAvailable() && 41 | rstudioapi::hasFun("documentSaveAll") 42 | ) { 43 | rstudioapi::documentSaveAll() 44 | } 45 | } 46 | 47 | # We'll look for the run_dev script in the current dir 48 | try_dev <- file.path( 49 | golem_wd, 50 | file 51 | ) 52 | 53 | # Stop if it doesn't exists 54 | if (file.exists(try_dev)) { 55 | run_dev_lines <- readLines(try_dev) 56 | } else { 57 | stop( 58 | "Unable to locate the run_dev-file passed via the 'file' argument." 59 | ) 60 | } 61 | 62 | if (install_required_packages) { 63 | install_dev_deps("attachment", force_install = install_required_packages) 64 | to_install <- attachment::att_from_rscript(path = try_dev) 65 | install_dev_deps( 66 | dev_deps = to_install, 67 | force_install = install_required_packages 68 | ) 69 | } 70 | 71 | eval( 72 | parse( 73 | text = run_dev_lines 74 | ) 75 | ) 76 | } 77 | -------------------------------------------------------------------------------- /R/sanity_check.R: -------------------------------------------------------------------------------- 1 | #' Sanity check for R files in the project 2 | #' 3 | #' This function is used check for any `browser()`` or commented 4 | #' #TODO / #TOFIX / #BUG in the code 5 | #' 6 | #' @inheritParams add_module 7 | #' 8 | #' @rdname sanity_check 9 | #' @export 10 | #' 11 | #' 12 | #' @return A DataFrame if any of the words has been found. 13 | sanity_check <- function( 14 | golem_wd = get_golem_wd(), 15 | pkg 16 | ) { 17 | signal_arg_is_deprecated( 18 | pkg, 19 | fun = as.character(sys.call()[[1]]), 20 | "pkg" 21 | ) 22 | all_R_files <- list.files( 23 | path = golem_wd, 24 | pattern = "\\.R$", 25 | recursive = TRUE, 26 | full.names = TRUE 27 | ) 28 | 29 | to_find <- c( 30 | "browser()", 31 | "#TODO", 32 | "#TOFIX", 33 | "#BUG", 34 | "# TODO", 35 | "# TOFIX", 36 | "# BUG" 37 | ) 38 | 39 | source_markers <- data.frame() 40 | 41 | for (file_name in all_R_files) { 42 | file <- readLines(file_name, warn = FALSE) 43 | 44 | for (word in to_find) { 45 | line_number <- grep(word, file, fixed = TRUE) 46 | if (length(line_number) > 0) { 47 | df <- data.frame( 48 | type = "warning", 49 | file = file_name, 50 | line = line_number, 51 | message = paste("Found", word, sep = " "), 52 | column = 1 53 | ) 54 | source_markers <- rbind.data.frame(source_markers, df) 55 | } 56 | } 57 | } 58 | if (length(source_markers) > 0) { 59 | if ( 60 | rlang::is_installed("rstudioapi") && 61 | rstudioapi::isAvailable() && 62 | rstudioapi::hasFun("sourceMarkers") 63 | ) { 64 | rstudioapi::sourceMarkers( 65 | "sanity_check", 66 | markers = source_markers 67 | ) 68 | } 69 | return(source_markers) 70 | } else { 71 | cat_green_tick("Sanity check passed successfully.") 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /R/templates.R: -------------------------------------------------------------------------------- 1 | #' Project Hook 2 | #' 3 | #' Project hooks allow to define a function run just after `{golem}` 4 | #' project creation. 5 | #' 6 | #' @inheritParams create_golem 7 | #' @param ... Arguments passed from `create_golem()`, unused in the default 8 | #' function. 9 | #' 10 | #' @return Used for side effects 11 | #' @export 12 | #' 13 | #' @examples 14 | #' if (interactive()) { 15 | #' my_proj <- function(...) { 16 | #' unlink("dev/", TRUE, TRUE) 17 | #' } 18 | #' create_golem("ici", project_template = my_proj) 19 | #' } 20 | project_hook <- function(path, package_name, ...) { 21 | return(TRUE) 22 | } 23 | 24 | #' Golem's default custom templates 25 | #' 26 | #' These functions do not aim at being called as is by 27 | #' users, but to be passed as an argument to the `add_js_handler()` 28 | #' function. 29 | #' 30 | #' @param path The path to the JS script where this template will be written. 31 | #' @param name Shiny's custom handler name. 32 | #' @param code JavaScript code to be written in the function. 33 | #' @return Used for side effect 34 | #' @rdname template 35 | #' @export 36 | #' @seealso [add_js_handler()] 37 | js_handler_template <- function( 38 | path, 39 | name = "fun", 40 | code = " " 41 | ) { 42 | write_there <- write_there_builder(path) 43 | 44 | write_there("$( document ).ready(function() {") 45 | write_there( 46 | sprintf(" Shiny.addCustomMessageHandler('%s', function(arg) {", name) 47 | ) 48 | write_there(code) 49 | write_there(" })") 50 | write_there("});") 51 | } 52 | 53 | #' @export 54 | #' @rdname template 55 | js_template <- function( 56 | path, 57 | code = " " 58 | ) { 59 | write_there <- write_there_builder(path) 60 | 61 | write_there(code) 62 | } 63 | 64 | #' @export 65 | #' @rdname template 66 | css_template <- function( 67 | path, 68 | code = " " 69 | ) { 70 | write_there <- write_there_builder(path) 71 | write_there(code) 72 | } 73 | 74 | #' @export 75 | #' @rdname template 76 | sass_template <- function( 77 | path, 78 | code = " " 79 | ) { 80 | write_there <- write_there_builder(path) 81 | 82 | write_there(code) 83 | } 84 | 85 | #' @export 86 | #' @rdname template 87 | empty_template <- function( 88 | path, 89 | code = " " 90 | ) { 91 | write_there <- write_there_builder(path) 92 | 93 | write_there(code) 94 | } 95 | -------------------------------------------------------------------------------- /R/use_files_external_tools.R: -------------------------------------------------------------------------------- 1 | check_url_has_the_correct_extension <- function( 2 | url, 3 | type = c("js", "css", "html") 4 | ) { 5 | type <- match.arg(type) 6 | if (file_ext(url) != type) { 7 | cli_cli_abort( 8 | paste0( 9 | "File not added (URL must end with .", 10 | type, 11 | " extension)" 12 | ) 13 | ) 14 | } 15 | } 16 | 17 | 18 | download_external <- function( 19 | url_to_download_from, 20 | where_to_download 21 | ) { 22 | cat_start_download() 23 | utils_download_file( 24 | url_to_download_from, 25 | where_to_download 26 | ) 27 | cat_downloaded(where_to_download) 28 | } 29 | 30 | perform_checks_and_download_if_everything_is_ok <- function( 31 | url_to_download_from, 32 | directory_to_download_to, 33 | file_type, 34 | file_created_fun, 35 | golem_wd, 36 | name, 37 | open, 38 | pkg 39 | ) { 40 | signal_arg_is_deprecated( 41 | pkg, 42 | fun = as.character(sys.call()[[1]]), 43 | "pkg" 44 | ) 45 | old <- setwd(fs_path_abs(golem_wd)) 46 | on.exit(setwd(old)) 47 | name <- build_name( 48 | name, 49 | url_to_download_from 50 | ) 51 | if (is.null(file_type)) { 52 | where_to_download_to <- fs_path( 53 | directory_to_download_to, 54 | name 55 | ) 56 | } else { 57 | check_url_has_the_correct_extension( 58 | url = url_to_download_from, 59 | file_type 60 | ) 61 | where_to_download_to <- fs_path( 62 | directory_to_download_to, 63 | sprintf( 64 | "%s.%s", 65 | name, 66 | file_type 67 | ) 68 | ) 69 | } 70 | check_directory_exists( 71 | directory_to_download_to 72 | ) 73 | check_file_exists( 74 | where_to_download_to 75 | ) 76 | download_external( 77 | url_to_download_from = url_to_download_from, 78 | where_to_download = where_to_download_to 79 | ) 80 | file_created_dance( 81 | where = where_to_download_to, 82 | fun = file_created_fun, 83 | golem_wd = golem_wd, 84 | dir = directory_to_download_to, 85 | open_file = open, 86 | catfun = cat_downloaded 87 | ) 88 | } 89 | -------------------------------------------------------------------------------- /R/use_files_internal_tools.R: -------------------------------------------------------------------------------- 1 | copy_internal_file <- function( 2 | path, 3 | where 4 | ) { 5 | cat_start_copy() 6 | 7 | fs_file_copy(path, where) 8 | 9 | cat_copied(where) 10 | } 11 | 12 | check_file_has_the_correct_extension <- function( 13 | path, 14 | type = c("js", "css", "html") 15 | ) { 16 | type <- match.arg(type) 17 | if (file_ext(path) != type) { 18 | cli_cli_abort( 19 | paste0( 20 | "File not added (URL must end with .", 21 | type, 22 | ")" 23 | ) 24 | ) 25 | } 26 | } 27 | 28 | perform_checks_and_copy_if_everything_is_ok <- function( 29 | path_to_copy_from, 30 | directory_to_copy_to, 31 | file_type, 32 | file_created_fun, 33 | golem_wd, 34 | name, 35 | open 36 | ) { 37 | old <- setwd(fs_path_abs(golem_wd)) 38 | on.exit(setwd(old)) 39 | if (is.null(file_type)) { 40 | name <- build_name( 41 | name, 42 | path_to_copy_from, 43 | with_ext = TRUE 44 | ) 45 | where_to_copy_to <- fs_path( 46 | directory_to_copy_to, 47 | name 48 | ) 49 | } else { 50 | name <- build_name( 51 | name, 52 | path_to_copy_from 53 | ) 54 | check_file_has_the_correct_extension( 55 | path = path_to_copy_from, 56 | file_type 57 | ) 58 | where_to_copy_to <- fs_path( 59 | directory_to_copy_to, 60 | sprintf( 61 | "%s.%s", 62 | name, 63 | file_type 64 | ) 65 | ) 66 | } 67 | check_directory_exists( 68 | directory_to_copy_to 69 | ) 70 | check_file_exists( 71 | where_to_copy_to 72 | ) 73 | copy_internal_file( 74 | path_to_copy_from, 75 | where_to_copy_to 76 | ) 77 | file_created_dance( 78 | where = where_to_copy_to, 79 | fun = after_creation_message_css, 80 | golem_wd = golem_wd, 81 | dir = directory_to_copy_to, 82 | open_file = open, 83 | catfun = cat_copied 84 | ) 85 | } 86 | -------------------------------------------------------------------------------- /R/use_files_shared_tools.R: -------------------------------------------------------------------------------- 1 | build_name <- function( 2 | name = NULL, 3 | url, 4 | with_ext = FALSE 5 | ) { 6 | if (is.null(name)) { 7 | name <- basename(url) 8 | } 9 | check_name_length_is_one(name) 10 | if (with_ext) { 11 | return(name) 12 | } 13 | return( 14 | file_path_sans_ext(name) 15 | ) 16 | } 17 | 18 | check_directory_exists <- function(dir) { 19 | if (!fs_dir_exists(dir)) { 20 | cli_cli_abort( 21 | sprintf( 22 | "The %s directory is required but does not exist.\n\nYou can create it with:\ndir.create('%s', recursive = TRUE)", 23 | dir, 24 | dir 25 | ) 26 | ) 27 | } 28 | } 29 | 30 | check_file_exists <- function(where) { 31 | if (fs_file_exists(where)) { 32 | cli_cli_abort( 33 | sprintf( 34 | "%s already exists.\n\nYou can delete it with:\nunlink('%s', recursive = TRUE).", 35 | where, 36 | where 37 | ) 38 | ) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /R/use_readme.R: -------------------------------------------------------------------------------- 1 | #' Generate a README.Rmd 2 | #' @inheritParams usethis::use_readme_rmd 3 | #' @inheritParams add_module 4 | #' @inheritParams fill_desc 5 | #' @param overwrite an optional \code{logical} flag; if \code{TRUE}, overwrite 6 | #' existing \code{README.Rmd}, else throws an error if \code{README.Rmd} exists 7 | #' 8 | #' @return pure side-effect function that generates template \code{README.Rmd} 9 | #' @export 10 | use_readme_rmd <- function( 11 | open = rlang::is_interactive(), 12 | pkg_name = golem::get_golem_name(), 13 | overwrite = FALSE, 14 | golem_wd = golem::get_golem_wd(), 15 | pkg 16 | ) { 17 | signal_arg_is_deprecated( 18 | pkg, 19 | fun = as.character(sys.call()[[1]]), 20 | "pkg" 21 | ) 22 | stopifnot(`Arg. 'overwrite' must be logical` = is.logical(overwrite)) 23 | 24 | # We move the working directory to perform this action, 25 | # in case we're launching the action from somewhere else 26 | old <- setwd(golem_wd) 27 | on.exit(setwd(old)) 28 | 29 | # Guess the readme path 30 | readme_path <- file.path( 31 | golem_wd, 32 | "README.Rmd" 33 | ) 34 | 35 | # Removing the README if it already exists and overwrite is TRUE 36 | check_overwrite( 37 | overwrite, 38 | readme_path 39 | ) 40 | 41 | usethis_use_readme_rmd(open = open) 42 | 43 | readme_tmpl <- generate_readme_tmpl( 44 | pkg_name = pkg_name 45 | ) 46 | 47 | write( 48 | x = readme_tmpl, 49 | file = readme_path, 50 | append = FALSE, 51 | sep = "\n" 52 | ) 53 | return(invisible(TRUE)) 54 | } 55 | 56 | check_overwrite <- function(overwrite, tmp_pth) { 57 | # If the user wants to overwrite, we remove the file 58 | # Otherwise, error if the file already exists 59 | if (file.exists(tmp_pth)) { 60 | if (isTRUE(overwrite)) { 61 | unlink(tmp_pth, TRUE, TRUE) 62 | } else { 63 | stop("README.Rmd already exists. Set `overwrite = TRUE` to overwrite.") 64 | } 65 | } 66 | } 67 | 68 | generate_readme_tmpl <- function(pkg_name) { 69 | tmp_file <- readLines( 70 | golem_sys("utils/empty_readme.Rmd") 71 | ) 72 | return( 73 | sprintf( 74 | tmp_file, 75 | pkg_name 76 | ) 77 | ) 78 | } 79 | -------------------------------------------------------------------------------- /R/use_recommended.R: -------------------------------------------------------------------------------- 1 | #' Add recommended elements 2 | #' 3 | #' \describe{ 4 | #' \item{use_recommended_deps}{Adds `shiny`, `DT`, `attempt`, `glue`, `golem`, `htmltools` to dependencies} 5 | #' \item{use_recommended_tests}{Adds a test folder and copy the golem tests} 6 | #' } 7 | #' 8 | #' @inheritParams add_module 9 | #' @inheritParams usethis::use_spell_check 10 | #' @param recommended A vector of recommended packages. 11 | #' @param spellcheck Whether or not to use a spellcheck test. 12 | #' 13 | #' @rdname use_recommended 14 | #' 15 | #' @export 16 | #' 17 | #' @return Used for side-effects. 18 | #' 19 | use_recommended_deps <- function( 20 | pkg = get_golem_wd(), 21 | recommended = c( 22 | "shiny", 23 | "DT", 24 | "attempt", 25 | "glue", 26 | "htmltools", 27 | "golem" 28 | ) 29 | ) { 30 | .Deprecated( 31 | old = "use_recommended_deps", 32 | msg = "use_recommended_deps() is currently soft deprecated and will be removed in future versions of {golem}." 33 | ) 34 | 35 | old <- setwd(fs_path_abs(pkg)) 36 | on.exit(setwd(old)) 37 | 38 | for (i in sort(recommended)) { 39 | try(usethis_use_package(i)) 40 | } 41 | 42 | cat_green_tick("Dependencies added") 43 | } 44 | 45 | 46 | #' @rdname use_recommended 47 | #' @export 48 | #' @importFrom utils capture.output 49 | #' @importFrom attempt without_warning stop_if 50 | use_recommended_tests <- function( 51 | golem_wd = get_golem_wd(), 52 | spellcheck = TRUE, 53 | vignettes = TRUE, 54 | lang = "en-US", 55 | error = FALSE, 56 | pkg 57 | ) { 58 | signal_arg_is_deprecated( 59 | pkg, 60 | fun = as.character(sys.call()[[1]]), 61 | "pkg" 62 | ) 63 | old <- setwd(fs_path_abs(golem_wd)) 64 | 65 | on.exit(setwd(old)) 66 | 67 | if ( 68 | !fs_dir_exists( 69 | fs_path(fs_path_abs(golem_wd), "tests") 70 | ) 71 | ) { 72 | without_warning(usethis_use_testthat)() 73 | } 74 | if (!requireNamespace("processx")) { 75 | stop( 76 | "Please install the {processx} package to add the recommended tests." 77 | ) 78 | } 79 | 80 | stop_if( 81 | fs_path( 82 | golem_wd, 83 | "tests", 84 | "testthat", 85 | "test-golem-recommended.R" 86 | ), 87 | fs_file_exists, 88 | "test-golem-recommended.R already exists. \nPlease remove it first if you need to reinsert it." 89 | ) 90 | 91 | fs_file_copy( 92 | golem_sys( 93 | "utils", 94 | "test-golem-recommended.R" 95 | ), 96 | fs_path( 97 | golem_wd, 98 | "tests", 99 | "testthat" 100 | ), 101 | overwrite = TRUE 102 | ) 103 | 104 | if (spellcheck) { 105 | usethis_use_spell_check( 106 | vignettes = vignettes, 107 | lang = lang, 108 | error = error 109 | ) 110 | } 111 | cat_green_tick("Tests added") 112 | } 113 | -------------------------------------------------------------------------------- /R/use_utils_tools.R: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/golem/3a5c7a46351f7fb3f8ba9d2e6b22a92c13d282c2/R/use_utils_tools.R -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | # R CMD check results 2 | 3 | 0 errors ✔ | 0 warnings ✔ | 0 notes ✔ 4 | 5 | # Revdeps results 6 | 7 | ## Failed to check (1) 8 | 9 | |package |version |error |warning |note | 10 | |:-----------|:-------|:-----|:-------|:----| 11 | |spatialLIBD |1.16.2 |1 | |1 | -------------------------------------------------------------------------------- /dev/config_attachment.yaml: -------------------------------------------------------------------------------- 1 | path.n: NAMESPACE 2 | path.d: DESCRIPTION 3 | dir.r: R 4 | dir.v: vignettes 5 | dir.t: tests 6 | extra.suggests: 7 | - pkgdown 8 | - purrr 9 | - rcmdcheck 10 | - covr 11 | - remotes 12 | - sass 13 | - cli 14 | - crayon 15 | - devtools 16 | - dockerfiler 17 | - knitr 18 | - pkgload 19 | - pkgbuild 20 | - pkgdown 21 | - processx 22 | - purrr 23 | - rcmdcheck 24 | - roxygen2 25 | - rmarkdown 26 | - rsconnect 27 | - spelling 28 | - stringr 29 | - testthat 30 | - tools 31 | - withr 32 | - mockery 33 | - attachment 34 | - renv 35 | - usethis 36 | - fs 37 | - rstudioapi 38 | - desc 39 | pkg_ignore: 40 | - s 41 | - pkg 42 | - i 43 | - covr 44 | - remotes 45 | - sass 46 | - cli 47 | - crayon 48 | - devtools 49 | - dockerfiler 50 | - knitr 51 | - pkgload 52 | - pkgbuild 53 | - pkgdown 54 | - processx 55 | - purrr 56 | - rcmdcheck 57 | - roxygen2 58 | - rmarkdown 59 | - rsconnect 60 | - spelling 61 | - stringr 62 | - testthat 63 | - tools 64 | - withr 65 | - mockery 66 | - attachment 67 | - renv 68 | - usethis 69 | - fs 70 | - rstudioapi 71 | - desc 72 | document: yes 73 | normalize: yes 74 | inside_rmd: no 75 | must.exist: yes 76 | check_if_suggests_is_installed: yes 77 | -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | Autoload 2 | C'est 3 | CDN 4 | CMD 5 | Cheatsheet 6 | CoC 7 | DESC 8 | DataFrame 9 | Dev 10 | Dockerfile 11 | Dockerfiles 12 | Golem's 13 | Hotfixing 14 | JS 15 | LICENCE 16 | Lifecycle 17 | ORCID 18 | Pilbery 19 | PositConnect 20 | README 21 | RStudio 22 | Rbuildignore 23 | Rmd 24 | Shiny's 25 | ShinyProxy 26 | Shinyapps 27 | TOFIX 28 | UI 29 | VSCode 30 | addins 31 | appObj 32 | arg 33 | args 34 | availabily 35 | behaviour 36 | benchmarking 37 | blogposts 38 | centos 39 | cheatsheet 40 | codebase 41 | conditionned 42 | css 43 | dans 44 | debian 45 | debounce 46 | deps 47 | des 48 | desc 49 | dev 50 | devtools 51 | dockerfile 52 | dockerfiler 53 | env 54 | exe 55 | explicitely 56 | favicon 57 | fct 58 | filesystem 59 | fs 60 | getters 61 | github 62 | gz 63 | hideid 64 | htmlDependency 65 | htmlTemplate 66 | https 67 | ico 68 | io 69 | jQuery 70 | js 71 | lifecycle 72 | matchine 73 | md 74 | mettre 75 | namespaced 76 | natively 77 | paillettes 78 | pak 79 | param 80 | params 81 | pkgbuild 82 | pkgdown 83 | pkgload 84 | png 85 | preconfigured 86 | preload 87 | processx 88 | projet 89 | quand 90 | que 91 | rconnect 92 | renv 93 | responsabily 94 | rlang 95 | roclet 96 | roxygen 97 | rsconnect 98 | rstudio 99 | rstudioapi 100 | shinyapp 101 | shinyproxy 102 | shinytemplate 103 | showid 104 | stylesheet 105 | subfolders 106 | testServer 107 | testthat 108 | tidyverse 109 | tu 110 | ui 111 | un 112 | usethis 113 | vas 114 | ver 115 | wd 116 | winlash 117 | www 118 | xenial 119 | yaml 120 | yml 121 | -------------------------------------------------------------------------------- /inst/img/golemtemplate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/golem/3a5c7a46351f7fb3f8ba9d2e6b22a92c13d282c2/inst/img/golemtemplate.png -------------------------------------------------------------------------------- /inst/rstudio/addins.dcf: -------------------------------------------------------------------------------- 1 | Name: Open start.R 2 | Description: Opens the 01_start.R file. 3 | Binding: go_to_start 4 | Interactive: false 5 | 6 | Name: Open dev.R 7 | Description: Opens the 02_dev.R file. 8 | Binding: go_to_dev 9 | Interactive: false 10 | 11 | Name: Open deploy.R 12 | Description: Opens the 03_deploy.R file. 13 | Binding: go_to_deploy 14 | Interactive: false 15 | 16 | Name: Open run_dev.R 17 | Description: Opens the run_dev.R file. 18 | Binding: go_to_run_dev 19 | Interactive: false 20 | 21 | Name: Open app_ui.R 22 | Description: Opens the app_ui.R file. 23 | Binding: go_to_app_ui 24 | Interactive: false 25 | 26 | Name: Open app_server.R 27 | Description: Opens the app_server.R file. 28 | Binding: go_to_app_server 29 | Interactive: false 30 | 31 | Name: Open run_app.R 32 | Description: Opens the run_app.R file. 33 | Binding: go_to_run_app 34 | 35 | Name: Put selected text into between ns() 36 | Description: add 'ns(' in front of selected text, and add ')' behind. 37 | Binding: insert_ns 38 | Interactive: false 39 | 40 | Name: Run run_dev.R 41 | Description: Runs the run_dev.R file. 42 | Binding: run_dev 43 | Interactive: true -------------------------------------------------------------------------------- /inst/rstudio/templates/project/create_golem.dcf: -------------------------------------------------------------------------------- 1 | Binding: create_golem_gui 2 | Title: Package for Shiny App using golem 3 | OpenFiles: dev/01_start.R 4 | Icon: golem.png 5 | 6 | Parameter: without_comments 7 | Widget: CheckboxInput 8 | Label: Start my project without golem comments 9 | Default: Off 10 | Position: left 11 | 12 | Parameter: project_hook 13 | Widget: TextInput 14 | Label: Hook function to run during project creation 15 | Default: golem::project_hook 16 | Position: left 17 | 18 | Parameter: check_name 19 | Widget: CheckboxInput 20 | Label: Perform a Check on the name 21 | Default: On 22 | Position: left 23 | 24 | Parameter: with_git 25 | Widget: CheckboxInput 26 | Label: Create a git repository 27 | Default: Off 28 | Position: left 29 | -------------------------------------------------------------------------------- /inst/rstudio/templates/project/golem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/golem/3a5c7a46351f7fb3f8ba9d2e6b22a92c13d282c2/inst/rstudio/templates/project/golem.png -------------------------------------------------------------------------------- /inst/rstudio/templates/project/shiny.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/golem/3a5c7a46351f7fb3f8ba9d2e6b22a92c13d282c2/inst/rstudio/templates/project/shiny.png -------------------------------------------------------------------------------- /inst/shinyexample/.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | inst/doc 6 | -------------------------------------------------------------------------------- /inst/shinyexample/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: shinyexample 2 | Title: An Amazing Shiny App 3 | Version: 0.0.0.9000 4 | Authors@R: 5 | person(given = "firstname", 6 | family = "lastname", 7 | role = c("aut", "cre"), 8 | email = "your@email.com") 9 | Description: What the package does (one paragraph). 10 | License: What license is it under? 11 | Imports: 12 | config, 13 | golem, 14 | shiny 15 | Encoding: UTF-8 16 | LazyData: true 17 | RoxygenNote: 7.1.1 18 | -------------------------------------------------------------------------------- /inst/shinyexample/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(run_app) 4 | import(shiny) 5 | importFrom(golem,activate_js) 6 | importFrom(golem,add_resource_path) 7 | importFrom(golem,bundle_resources) 8 | importFrom(golem,favicon) 9 | importFrom(golem,with_golem_options) 10 | importFrom(shiny,shinyApp) 11 | -------------------------------------------------------------------------------- /inst/shinyexample/R/app_config.R: -------------------------------------------------------------------------------- 1 | #' Access files in the current app 2 | #' 3 | #' NOTE: If you manually change your package name in the DESCRIPTION, 4 | #' don't forget to change it here too, and in the config file. 5 | #' For a safer name change mechanism, use the `golem::set_golem_name()` function. 6 | #' 7 | #' @param ... character vectors, specifying subdirectory and file(s) 8 | #' within your package. The default, none, returns the root of the app. 9 | #' 10 | #' @noRd 11 | app_sys <- function(...) { 12 | system.file(..., package = "shinyexample") 13 | } 14 | 15 | 16 | #' Read App Config 17 | #' 18 | #' @param value Value to retrieve from the config file. 19 | #' @param config GOLEM_CONFIG_ACTIVE value. If unset, R_CONFIG_ACTIVE. 20 | #' If unset, "default". 21 | #' @param use_parent Logical, scan the parent directory for config file. 22 | #' @param file Location of the config file 23 | #' 24 | #' @noRd 25 | get_golem_config <- function( 26 | value, 27 | config = Sys.getenv( 28 | "GOLEM_CONFIG_ACTIVE", 29 | Sys.getenv( 30 | "R_CONFIG_ACTIVE", 31 | "default" 32 | ) 33 | ), 34 | use_parent = TRUE, 35 | # If you don't want to use the default config file, 36 | # set a `GOLEM_CONFIG_PATH` environment variable that points 37 | # to your custom config file. 38 | file = Sys.getenv( 39 | "GOLEM_CONFIG_PATH", 40 | app_sys("golem-config.yml") 41 | ) 42 | ) { 43 | config::get( 44 | value = value, 45 | config = config, 46 | file = file, 47 | use_parent = use_parent 48 | ) 49 | } 50 | -------------------------------------------------------------------------------- /inst/shinyexample/R/app_server.R: -------------------------------------------------------------------------------- 1 | #' The application server-side 2 | #' 3 | #' @param input,output,session Internal parameters for {shiny}. 4 | #' DO NOT REMOVE. 5 | #' @import shiny 6 | #' @noRd 7 | app_server <- function(input, output, session) { 8 | # Your application server logic 9 | } 10 | -------------------------------------------------------------------------------- /inst/shinyexample/R/app_ui.R: -------------------------------------------------------------------------------- 1 | #' The application User-Interface 2 | #' 3 | #' @param request Internal parameter for `{shiny}`. 4 | #' DO NOT REMOVE. 5 | #' @import shiny 6 | #' @noRd 7 | app_ui <- function(request) { 8 | tagList( 9 | # Leave this function for adding external resources 10 | golem_add_external_resources(), 11 | # Your application UI logic 12 | fluidPage( 13 | golem::golem_welcome_page() # Remove this line to start building your UI 14 | ) 15 | ) 16 | } 17 | 18 | #' Add external Resources to the Application 19 | #' 20 | #' This function is internally used to add external 21 | #' resources inside the Shiny application. 22 | #' 23 | #' @import shiny 24 | #' @importFrom golem add_resource_path activate_js favicon bundle_resources 25 | #' @noRd 26 | golem_add_external_resources <- function() { 27 | add_resource_path( 28 | "www", 29 | app_sys("app/www") 30 | ) 31 | 32 | tags$head( 33 | favicon(), 34 | bundle_resources( 35 | path = app_sys("app/www"), 36 | app_title = "shinyexample" 37 | ) 38 | # Add here other external resources 39 | # for example, you can add shinyalert::useShinyalert() 40 | ) 41 | } 42 | -------------------------------------------------------------------------------- /inst/shinyexample/R/run_app.R: -------------------------------------------------------------------------------- 1 | #' Run the Shiny Application 2 | #' 3 | #' @param ... arguments to pass to golem_opts. 4 | #' See `?golem::get_golem_options` for more details. 5 | #' @inheritParams shiny::shinyApp 6 | #' 7 | #' @export 8 | #' @importFrom shiny shinyApp 9 | #' @importFrom golem with_golem_options 10 | run_app <- function( 11 | onStart = NULL, 12 | options = list(), 13 | enableBookmarking = NULL, 14 | uiPattern = "/", 15 | ... 16 | ) { 17 | with_golem_options( 18 | app = shinyApp( 19 | ui = app_ui, 20 | server = app_server, 21 | onStart = onStart, 22 | options = options, 23 | enableBookmarking = enableBookmarking, 24 | uiPattern = uiPattern 25 | ), 26 | golem_opts = list(...) 27 | ) 28 | } 29 | -------------------------------------------------------------------------------- /inst/shinyexample/REMOVEME.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^data-raw$ 4 | dev_history.R 5 | ^dev$ 6 | $run_dev.* 7 | ^.here$ 8 | -------------------------------------------------------------------------------- /inst/shinyexample/dev/02_dev.R: -------------------------------------------------------------------------------- 1 | # Building a Prod-Ready, Robust Shiny Application. 2 | # 3 | # README: each step of the dev files is optional, and you don't have to 4 | # fill every dev scripts before getting started. 5 | # 01_start.R should be filled at start. 6 | # 02_dev.R should be used to keep track of your development during the project. 7 | # 03_deploy.R should be used once you need to deploy your app. 8 | # 9 | # 10 | ################################### 11 | #### CURRENT FILE: DEV SCRIPT ##### 12 | ################################### 13 | 14 | # Engineering 15 | 16 | ## Dependencies ---- 17 | ## Amend DESCRIPTION with dependencies read from package code parsing 18 | ## install.packages('attachment') # if needed. 19 | attachment::att_amend_desc() 20 | 21 | ## Add modules ---- 22 | ## Create a module infrastructure in R/ 23 | golem::add_module(name = "name_of_module1", with_test = TRUE) # Name of the module 24 | golem::add_module(name = "name_of_module2", with_test = TRUE) # Name of the module 25 | 26 | ## Add helper functions ---- 27 | ## Creates fct_* and utils_* 28 | golem::add_fct("helpers", with_test = TRUE) 29 | golem::add_utils("helpers", with_test = TRUE) 30 | 31 | ## External resources 32 | ## Creates .js and .css files at inst/app/www 33 | golem::add_js_file("script") 34 | golem::add_js_handler("handlers") 35 | golem::add_css_file("custom") 36 | golem::add_sass_file("custom") 37 | golem::add_empty_file("file.json") 38 | 39 | ## Add internal datasets ---- 40 | ## If you have data in your package 41 | usethis::use_data_raw(name = "my_dataset", open = FALSE) 42 | 43 | ## Tests ---- 44 | ## Add one line by test you want to create 45 | usethis::use_test("app") 46 | 47 | # Documentation 48 | 49 | ## Vignette ---- 50 | usethis::use_vignette("shinyexample") 51 | devtools::build_vignettes() 52 | 53 | ## Code Coverage---- 54 | ## Set the code coverage service ("codecov" or "coveralls") 55 | usethis::use_coverage() 56 | 57 | # Create a summary readme for the testthat subdirectory 58 | covrpage::covrpage() 59 | 60 | ## CI ---- 61 | ## Use this part of the script if you need to set up a CI 62 | ## service for your application 63 | ## 64 | ## (You'll need GitHub there) 65 | usethis::use_github() 66 | 67 | # GitHub Actions 68 | usethis::use_github_action() 69 | # Chose one of the three 70 | # See https://usethis.r-lib.org/reference/use_github_action.html 71 | usethis::use_github_action_check_release() 72 | usethis::use_github_action_check_standard() 73 | usethis::use_github_action_check_full() 74 | # Add action for PR 75 | usethis::use_github_action_pr_commands() 76 | 77 | # Circle CI 78 | usethis::use_circleci() 79 | usethis::use_circleci_badge() 80 | 81 | # Jenkins 82 | usethis::use_jenkins() 83 | 84 | # GitLab CI 85 | usethis::use_gitlab_ci() 86 | 87 | # You're now set! ---- 88 | # go to dev/03_deploy.R 89 | rstudioapi::navigateToFile("dev/03_deploy.R") 90 | -------------------------------------------------------------------------------- /inst/shinyexample/dev/03_deploy.R: -------------------------------------------------------------------------------- 1 | # Building a Prod-Ready, Robust Shiny Application. 2 | # 3 | # README: each step of the dev files is optional, and you don't have to 4 | # fill every dev scripts before getting started. 5 | # 01_start.R should be filled at start. 6 | # 02_dev.R should be used to keep track of your development during the project. 7 | # 03_deploy.R should be used once you need to deploy your app. 8 | # 9 | # 10 | ###################################### 11 | #### CURRENT FILE: DEPLOY SCRIPT ##### 12 | ###################################### 13 | 14 | # Test your app 15 | 16 | ## Run checks ---- 17 | ## Check the package before sending to prod 18 | devtools::check() 19 | rhub::check_for_cran() 20 | 21 | # Deploy 22 | 23 | ## Local, CRAN or Package Manager ---- 24 | ## This will build a tar.gz that can be installed locally, 25 | ## sent to CRAN, or to a package manager 26 | devtools::build() 27 | 28 | ## Docker ---- 29 | ## If you want to deploy via a generic Dockerfile 30 | golem::add_dockerfile_with_renv() 31 | ## If you want to deploy to ShinyProxy 32 | golem::add_dockerfile_with_renv_shinyproxy() 33 | 34 | ## Posit ---- 35 | ## If you want to deploy on Posit related platforms 36 | golem::add_positconnect_file() 37 | golem::add_shinyappsio_file() 38 | golem::add_shinyserver_file() 39 | 40 | ## Deploy to Posit Connect or ShinyApps.io ---- 41 | 42 | ## Add/update manifest file (optional; for Git backed deployment on Posit ) 43 | rsconnect::writeManifest() 44 | 45 | ## In command line. 46 | rsconnect::deployApp( 47 | appName = desc::desc_get_field("Package"), 48 | appTitle = desc::desc_get_field("Package"), 49 | appFiles = c( 50 | # Add any additional files unique to your app here. 51 | "R/", 52 | "inst/", 53 | "data/", 54 | "NAMESPACE", 55 | "DESCRIPTION", 56 | "app.R" 57 | ), 58 | appId = rsconnect::deployments(".")$appID, 59 | lint = FALSE, 60 | forceUpdate = TRUE 61 | ) 62 | -------------------------------------------------------------------------------- /inst/shinyexample/dev/run_dev.R: -------------------------------------------------------------------------------- 1 | # Set options here 2 | options(golem.app.prod = FALSE) # TRUE = production mode, FALSE = development mode 3 | 4 | # Comment this if you don't want the app to be served on a random port 5 | options(shiny.port = httpuv::randomPort()) 6 | 7 | # Detach all loaded packages and clean your environment 8 | golem::detach_all_attached() 9 | # rm(list=ls(all.names = TRUE)) 10 | 11 | # Document and reload your package 12 | golem::document_and_reload() 13 | 14 | # Run the application 15 | run_app() 16 | -------------------------------------------------------------------------------- /inst/shinyexample/inst/app/www/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/golem/3a5c7a46351f7fb3f8ba9d2e6b22a92c13d282c2/inst/shinyexample/inst/app/www/favicon.ico -------------------------------------------------------------------------------- /inst/shinyexample/inst/golem-config.yml: -------------------------------------------------------------------------------- 1 | default: 2 | golem_name: shinyexample 3 | golem_version: 0.0.0.9000 4 | app_prod: no 5 | 6 | production: 7 | app_prod: yes 8 | 9 | dev: 10 | golem_wd: !expr golem::pkg_path() 11 | 12 | -------------------------------------------------------------------------------- /inst/shinyexample/man/run_app.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/run_app.R 3 | \name{run_app} 4 | \alias{run_app} 5 | \title{Run the Shiny Application} 6 | \usage{ 7 | run_app( 8 | onStart = NULL, 9 | options = list(), 10 | enableBookmarking = NULL, 11 | uiPattern = "/", 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{onStart}{A function that will be called before the app is actually run. 17 | This is only needed for \code{shinyAppObj}, since in the \code{shinyAppDir} 18 | case, a \code{global.R} file can be used for this purpose.} 19 | 20 | \item{options}{Named options that should be passed to the \code{runApp} call 21 | (these can be any of the following: "port", "launch.browser", "host", "quiet", 22 | "display.mode" and "test.mode"). You can also specify \code{width} and 23 | \code{height} parameters which provide a hint to the embedding environment 24 | about the ideal height/width for the app.} 25 | 26 | \item{enableBookmarking}{Can be one of \code{"url"}, \code{"server"}, or 27 | \code{"disable"}. The default value, \code{NULL}, will respect the setting from 28 | any previous calls to \code{\link[shiny:enableBookmarking]{enableBookmarking()}}. See \code{\link[shiny:enableBookmarking]{enableBookmarking()}} 29 | for more information on bookmarking your app.} 30 | 31 | \item{uiPattern}{A regular expression that will be applied to each \code{GET} 32 | request to determine whether the \code{ui} should be used to handle the 33 | request. Note that the entire request path must match the regular 34 | expression in order for the match to be considered successful.} 35 | 36 | \item{...}{arguments to pass to golem_opts. 37 | See `?golem::get_golem_options` for more details.} 38 | } 39 | \description{ 40 | Run the Shiny Application 41 | } 42 | -------------------------------------------------------------------------------- /inst/to-do-after-merge-dev.R: -------------------------------------------------------------------------------- 1 | desc::desc_bump_version("patch") 2 | rstudioapi::navigateToFile("NEWS.md") 3 | devtools::build_readme() 4 | gert::git_add(c("DESCRIPTION", "NEWS.md", "README.md", "NEWS.md")) 5 | gert::git_commit("chore: version bump & news update") 6 | gert::git_push() 7 | -------------------------------------------------------------------------------- /inst/utils/empty_readme.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%%" 13 | ) 14 | ``` 15 | 16 | # `{%s}` 17 | 18 | 19 | 20 | 21 | ## Installation 22 | 23 | You can install the development version of `{%s}` like so: 24 | 25 | ```{r} 26 | # FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE? 27 | ``` 28 | 29 | ## Run 30 | 31 | You can launch the application by running: 32 | 33 | ```{r, eval = FALSE} 34 | %s::run_app() 35 | ``` 36 | 37 | ## About 38 | 39 | You are reading the doc about version : `r golem::pkg_version()` 40 | 41 | This README has been compiled on the 42 | 43 | ```{r} 44 | Sys.time() 45 | ``` 46 | 47 | Here are the tests results and package coverage: 48 | 49 | ```{r, error = TRUE} 50 | devtools::check(quiet = TRUE) 51 | ``` 52 | 53 | ```{r echo = FALSE} 54 | unloadNamespace("%s") 55 | ``` 56 | 57 | ```{r, error = TRUE} 58 | covr::package_coverage() 59 | ``` 60 | -------------------------------------------------------------------------------- /inst/utils/golem-js.js: -------------------------------------------------------------------------------- 1 | $( document ).ready(function() { 2 | Shiny.addCustomMessageHandler('show', function(what) { 3 | $(what).show(); 4 | }); 5 | 6 | Shiny.addCustomMessageHandler('hide', function(what) { 7 | $(what).hide(); 8 | }); 9 | 10 | Shiny.addCustomMessageHandler('showid', function(what) { 11 | $("#" + what).show(); 12 | }); 13 | 14 | Shiny.addCustomMessageHandler('hideid', function(what) { 15 | $("#" + what).hide(); 16 | }); 17 | 18 | Shiny.addCustomMessageHandler('showclass', function(what) { 19 | $("." + what).show(); 20 | }); 21 | 22 | Shiny.addCustomMessageHandler('hideclass', function(what) { 23 | $("." + what).hide(); 24 | }); 25 | 26 | Shiny.addCustomMessageHandler('showhref', function(what) { 27 | $("a[href*=" + what).show(); 28 | }); 29 | 30 | Shiny.addCustomMessageHandler('hidehref', function(what) { 31 | $("a[href*=" + what).hide(); 32 | }); 33 | 34 | Shiny.addCustomMessageHandler('clickon', function(what) { 35 | $(what).click(); 36 | }); 37 | 38 | Shiny.addCustomMessageHandler('disable', function(what) { 39 | $(what).attr('disabled', 'disabled'); 40 | }); 41 | 42 | Shiny.addCustomMessageHandler('reable', function(what) { 43 | $(what).removeAttr('disabled'); 44 | }); 45 | 46 | Shiny.addCustomMessageHandler('alert', function(message) { 47 | alert(message); 48 | }); 49 | 50 | Shiny.addCustomMessageHandler('prompt', function(args) { 51 | var input = prompt(args.message); 52 | Shiny.setInputValue(args.id, input); 53 | return input; 54 | }); 55 | 56 | Shiny.addCustomMessageHandler('confirm', function(args) { 57 | var input = confirm(args.message); 58 | Shiny.setInputValue(args.id, input); 59 | return input; 60 | }); 61 | 62 | }); 63 | 64 | 65 | -------------------------------------------------------------------------------- /inst/utils/golem_utils_server.R: -------------------------------------------------------------------------------- 1 | #' Inverted versions of in, is.null and is.na 2 | #' 3 | #' @noRd 4 | #' 5 | #' @examples 6 | #' 1 %not_in% 1:10 7 | #' not_null(NULL) 8 | `%not_in%` <- Negate(`%in%`) 9 | 10 | not_null <- Negate(is.null) 11 | 12 | not_na <- Negate(is.na) 13 | 14 | #' Removes the null from a vector 15 | #' 16 | #' @noRd 17 | #' 18 | #' @example 19 | #' drop_nulls(list(1, NULL, 2)) 20 | drop_nulls <- function(x) { 21 | x[!sapply(x, is.null)] 22 | } 23 | 24 | #' If x is `NULL`, return y, otherwise return x 25 | #' 26 | #' @param x,y Two elements to test, one potentially `NULL` 27 | #' 28 | #' @noRd 29 | #' 30 | #' @examples 31 | #' NULL %||% 1 32 | "%||%" <- function(x, y) { 33 | if (is.null(x)) { 34 | y 35 | } else { 36 | x 37 | } 38 | } 39 | 40 | #' If x is `NA`, return y, otherwise return x 41 | #' 42 | #' @param x,y Two elements to test, one potentially `NA` 43 | #' 44 | #' @noRd 45 | #' 46 | #' @examples 47 | #' NA %|NA|% 1 48 | "%|NA|%" <- function(x, y) { 49 | if (is.na(x)) { 50 | y 51 | } else { 52 | x 53 | } 54 | } 55 | 56 | #' Typing reactiveValues is too long 57 | #' 58 | #' @inheritParams reactiveValues 59 | #' @inheritParams reactiveValuesToList 60 | #' 61 | #' @noRd 62 | rv <- function(...) shiny::reactiveValues(...) 63 | rvtl <- function(...) shiny::reactiveValuesToList(...) 64 | -------------------------------------------------------------------------------- /inst/utils/test-golem-recommended.R: -------------------------------------------------------------------------------- 1 | test_that("app ui", { 2 | ui <- app_ui() 3 | golem::expect_shinytaglist(ui) 4 | # Check that formals have not been removed 5 | fmls <- formals(app_ui) 6 | for (i in c("request")) { 7 | expect_true(i %in% names(fmls)) 8 | } 9 | }) 10 | 11 | test_that("app server", { 12 | server <- app_server 13 | expect_type(server, "closure") 14 | # Check that formals have not been removed 15 | fmls <- formals(app_server) 16 | for (i in c("input", "output", "session")) { 17 | expect_true(i %in% names(fmls)) 18 | } 19 | }) 20 | 21 | test_that( 22 | "app_sys works", 23 | { 24 | expect_true( 25 | app_sys("golem-config.yml") != "" 26 | ) 27 | } 28 | ) 29 | 30 | test_that( 31 | "golem-config works", 32 | { 33 | config_file <- app_sys("golem-config.yml") 34 | skip_if(config_file == "") 35 | 36 | expect_true( 37 | get_golem_config( 38 | "app_prod", 39 | config = "production", 40 | file = config_file 41 | ) 42 | ) 43 | expect_false( 44 | get_golem_config( 45 | "app_prod", 46 | config = "dev", 47 | file = config_file 48 | ) 49 | ) 50 | } 51 | ) 52 | 53 | # Configure this test to fit your need. 54 | # testServer() function makes it possible to test code in server functions and modules, without needing to run the full Shiny application 55 | testServer(app_server, { 56 | 57 | # Set and test an input 58 | session$setInputs(x = 2) 59 | expect_equal(input$x, 2) 60 | 61 | # Example of tests you can do on the server: 62 | # - Checking reactiveValues 63 | # expect_equal(r$lg, 'EN') 64 | # - Checking output 65 | # expect_equal(output$txt, "Text") 66 | }) 67 | 68 | # Configure this test to fit your need 69 | test_that( 70 | "app launches", 71 | { 72 | golem::expect_running(sleep = 5) 73 | } 74 | ) 75 | -------------------------------------------------------------------------------- /inst/utils/test-golem_utils_server.R: -------------------------------------------------------------------------------- 1 | test_that("not_in works", { 2 | expect_true(1 %not_in% 2:10) 3 | expect_false(1 %not_in% 1:10) 4 | }) 5 | 6 | test_that("not_null works", { 7 | expect_true(not_null(1)) 8 | expect_false(not_null(NULL)) 9 | }) 10 | 11 | test_that("not_na works", { 12 | expect_true(not_na(1)) 13 | expect_false(not_na(NA)) 14 | }) 15 | 16 | test_that("drop_nulls works", { 17 | expect_equal( 18 | drop_nulls( 19 | list(x = NULL, y = 2) 20 | ), 21 | list(y = 2) 22 | ) 23 | }) 24 | 25 | test_that("%||% works", { 26 | expect_equal( 27 | NULL %||% 1, 28 | 1 29 | ) 30 | expect_equal( 31 | 2 %||% 1, 32 | 2 33 | ) 34 | }) 35 | 36 | test_that("%|NA|% works", { 37 | expect_equal( 38 | NA %|NA|% 1, 39 | 1 40 | ) 41 | expect_equal( 42 | 2 %|NA|% 1, 43 | 2 44 | ) 45 | }) 46 | 47 | test_that("rv and rvtl work", { 48 | expect_true( 49 | inherits(rv, "function") 50 | ) 51 | expect_true( 52 | inherits(rvtl, "function") 53 | ) 54 | 55 | rv_test_1 <- rv(a = "a", b = 2) 56 | rv_test_2 <- reactiveValues(a = "a", b = 2) 57 | shiny::reactiveConsole(TRUE) 58 | expect_identical(rv_test_1$a, rv_test_2$a) 59 | expect_identical(rv_test_1$b, rv_test_2$b) 60 | expect_identical( 61 | rvtl(rv_test_2), 62 | shiny::reactiveValuesToList(rv_test_1) 63 | ) 64 | shiny::reactiveConsole(FALSE) 65 | }) 66 | -------------------------------------------------------------------------------- /inst/utils/testfile_template_css.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: lightblue; 3 | } 4 | 5 | h1 { 6 | color: white; 7 | text-align: center; 8 | } 9 | 10 | p { 11 | font-family: verdana; 12 | font-size: 20px; 13 | } 14 | -------------------------------------------------------------------------------- /inst/utils/testfile_template_html.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |My first paragraph.
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /inst/utils/testfile_template_js.js: -------------------------------------------------------------------------------- 1 | const myHeading = document.querySelector("h1"); 2 | myHeading.textContent = "Hello world!"; 3 | -------------------------------------------------------------------------------- /inst/utils/testfile_template_plainfile.txt: -------------------------------------------------------------------------------- 1 | Some text. 2 | -------------------------------------------------------------------------------- /man/add_module.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modules_fn.R 3 | \name{add_module} 4 | \alias{add_module} 5 | \title{Create a module} 6 | \usage{ 7 | add_module( 8 | name, 9 | golem_wd = get_golem_wd(), 10 | open = TRUE, 11 | dir_create = TRUE, 12 | fct = NULL, 13 | utils = NULL, 14 | r6 = NULL, 15 | js = NULL, 16 | js_handler = NULL, 17 | export = FALSE, 18 | module_template = golem::module_template, 19 | with_test = FALSE, 20 | ..., 21 | pkg 22 | ) 23 | } 24 | \arguments{ 25 | \item{name}{The name of the module.} 26 | 27 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 28 | 29 | \item{open}{Should the created file be opened?} 30 | 31 | \item{dir_create}{Creates the directory if it doesn't exist, default is \code{TRUE}.} 32 | 33 | \item{fct}{If specified, creates a \code{mod_fct} file.} 34 | 35 | \item{utils}{If specified, creates a \code{mod_utils} file.} 36 | 37 | \item{r6}{If specified, creates a \code{mod_class} file.} 38 | 39 | \item{js, js_handler}{If specified, creates a module related JavaScript file.} 40 | 41 | \item{export}{Should the module be exported? Default is \code{FALSE}.} 42 | 43 | \item{module_template}{Function that serves as a module template.} 44 | 45 | \item{with_test}{should the module be created with tests?} 46 | 47 | \item{...}{Arguments to be passed to the \code{module_template} function.} 48 | 49 | \item{pkg}{Deprecated, please use golem_wd instead} 50 | } 51 | \value{ 52 | The path to the file, invisibly. 53 | } 54 | \description{ 55 | This function creates a module inside the \verb{R/} folder, based 56 | on a specific module structure. This function can be used outside 57 | of a \code{{golem}} project. 58 | } 59 | \note{ 60 | This function will prefix the \code{name} argument with \code{mod_}. 61 | } 62 | \seealso{ 63 | \code{\link[=module_template]{module_template()}} 64 | } 65 | -------------------------------------------------------------------------------- /man/add_resource_path.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add_resource_path.R 3 | \name{add_resource_path} 4 | \alias{add_resource_path} 5 | \title{Add resource path} 6 | \usage{ 7 | add_resource_path(prefix, directoryPath, warn_empty = FALSE) 8 | } 9 | \arguments{ 10 | \item{prefix}{The URL prefix (without slashes). Valid characters are a-z, 11 | A-Z, 0-9, hyphen, period, and underscore. For example, a value of 'foo' 12 | means that any request paths that begin with '/foo' will be mapped to the 13 | given directory.} 14 | 15 | \item{directoryPath}{The directory that contains the static resources to be 16 | served.} 17 | 18 | \item{warn_empty}{Boolean. Default is \code{FALSE}. 19 | If TRUE display message if directory is empty.} 20 | } 21 | \value{ 22 | Used for side effects. 23 | } 24 | \description{ 25 | Add resource path 26 | } 27 | -------------------------------------------------------------------------------- /man/addins.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/addins.R 3 | \name{addins} 4 | \alias{addins} 5 | \alias{insert_ns} 6 | \alias{go_to_start} 7 | \alias{go_to_dev} 8 | \alias{go_to_deploy} 9 | \alias{go_to_run_dev} 10 | \alias{go_to_app_ui} 11 | \alias{go_to_app_server} 12 | \alias{go_to_run_app} 13 | \title{\code{{golem}} addins} 14 | \usage{ 15 | insert_ns() 16 | 17 | go_to_start(golem_wd = golem::get_golem_wd(), wd) 18 | 19 | go_to_dev(golem_wd = golem::get_golem_wd(), wd) 20 | 21 | go_to_deploy(golem_wd = golem::get_golem_wd(), wd) 22 | 23 | go_to_run_dev(golem_wd = golem::get_golem_wd(), wd) 24 | 25 | go_to_app_ui(golem_wd = golem::get_golem_wd(), wd) 26 | 27 | go_to_app_server(golem_wd = golem::get_golem_wd(), wd) 28 | 29 | go_to_run_app(golem_wd = golem::get_golem_wd(), wd) 30 | } 31 | \arguments{ 32 | \item{golem_wd}{The working directory of the \code{{golem}} application.} 33 | 34 | \item{wd}{Deperecated. Use \code{golem_wd} instead.} 35 | } 36 | \description{ 37 | \code{insert_ns()} takes a selected character vector and wrap it in \code{ns()} 38 | The series of \verb{go_to_*()} addins help you go to 39 | common files used in developing a \code{{golem}} application. 40 | } 41 | -------------------------------------------------------------------------------- /man/amend_golem_config.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/golem-yaml-utils.R 3 | \name{amend_golem_config} 4 | \alias{amend_golem_config} 5 | \title{Amend golem config file} 6 | \usage{ 7 | amend_golem_config( 8 | key, 9 | value, 10 | config = "default", 11 | golem_wd = golem::pkg_path(), 12 | talkative = TRUE, 13 | pkg 14 | ) 15 | } 16 | \arguments{ 17 | \item{key}{key of the value to add in \code{config}} 18 | 19 | \item{value}{Name of value (\code{NULL} to read all values)} 20 | 21 | \item{config}{Name of configuration to read from. Defaults to 22 | the value of the \code{R_CONFIG_ACTIVE} environment variable 23 | ("default" if the variable does not exist).} 24 | 25 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 26 | 27 | \item{talkative}{Should the messages be printed to the console?} 28 | 29 | \item{pkg}{Deprecated, please use golem_wd instead} 30 | } 31 | \value{ 32 | Used for side effects. 33 | } 34 | \description{ 35 | Amend golem config file 36 | } 37 | -------------------------------------------------------------------------------- /man/browser_button.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/browser_button.R 3 | \name{browser_button} 4 | \alias{browser_button} 5 | \title{Insert an hidden browser button} 6 | \usage{ 7 | browser_button() 8 | } 9 | \value{ 10 | Used for side effects. 11 | Prints the code to the console. 12 | } 13 | \description{ 14 | See \url{https://rtask.thinkr.fr/a-little-trick-for-debugging-shiny/} for more context. 15 | } 16 | -------------------------------------------------------------------------------- /man/bundle_resources.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bundle_resources.R 3 | \name{bundle_resources} 4 | \alias{bundle_resources} 5 | \title{Automatically serve golem external resources} 6 | \usage{ 7 | bundle_resources( 8 | path, 9 | app_title, 10 | name = "golem_resources", 11 | version = "0.0.1", 12 | meta = NULL, 13 | head = NULL, 14 | attachment = NULL, 15 | package = NULL, 16 | all_files = TRUE, 17 | app_builder = "golem", 18 | with_sparkles = FALSE, 19 | activate_js = TRUE 20 | ) 21 | } 22 | \arguments{ 23 | \item{path}{The path to the folder where the external files are located.} 24 | 25 | \item{app_title}{The title of the app, to be used as an application title.} 26 | 27 | \item{name}{Library name} 28 | 29 | \item{version}{Library version} 30 | 31 | \item{meta}{Named list of meta tags to insert into document head} 32 | 33 | \item{head}{Arbitrary lines of HTML to insert into the document head} 34 | 35 | \item{attachment}{Attachment(s) to include within the document head. See 36 | Details.} 37 | 38 | \item{package}{An R package name to indicate where to find the \code{src} 39 | directory when \code{src} is a relative path (see 40 | \code{\link[htmltools:resolveDependencies]{resolveDependencies()}}).} 41 | 42 | \item{all_files}{Whether all files under the \code{src} directory are 43 | dependency files. If \code{FALSE}, only the files specified in 44 | \code{script}, \code{stylesheet}, and \code{attachment} are treated as 45 | dependency files.} 46 | 47 | \item{app_builder}{The name of the app builder to add as a meta tag. 48 | Turn to NULL if you don't want this meta tag to be included.} 49 | 50 | \item{with_sparkles}{C'est quand que tu vas mettre des paillettes dans ma vie Kevin?} 51 | 52 | \item{activate_js}{Boolean to enable or disable the injection of JavaScript via activate_js().} 53 | } 54 | \value{ 55 | an htmlDependency 56 | } 57 | \description{ 58 | This function is a wrapper around \code{htmltools::htmlDependency} that 59 | automatically bundles the CSS and JavaScript files in \code{inst/app/www} 60 | and which are created by \code{golem::add_css_file()} , \code{golem::add_js_file()} 61 | and \code{golem::add_js_handler()}. 62 | } 63 | \details{ 64 | This function also preload \code{\link[=activate_js]{activate_js()}} which allows to 65 | use preconfigured JavaScript functions via \code{\link[=invoke_js]{invoke_js()}}. 66 | } 67 | -------------------------------------------------------------------------------- /man/create_golem.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create_golem.R 3 | \name{create_golem} 4 | \alias{create_golem} 5 | \title{Create a package for a Shiny App using \code{{golem}}} 6 | \usage{ 7 | create_golem( 8 | path, 9 | check_name = TRUE, 10 | open = TRUE, 11 | overwrite = FALSE, 12 | package_name = basename(normalizePath(path, mustWork = FALSE)), 13 | without_comments = FALSE, 14 | project_hook = golem::project_hook, 15 | with_git = FALSE, 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{path}{Name of the folder to create the package in. 21 | This will also be used as the package name.} 22 | 23 | \item{check_name}{Should we check that the package name is 24 | correct according to CRAN requirements.} 25 | 26 | \item{open}{Boolean. Open the created project?} 27 | 28 | \item{overwrite}{Boolean. Should the already existing project be deleted and replaced?} 29 | 30 | \item{package_name}{Package name to use. By default, \code{{golem}} uses 31 | \code{basename(path)}. If \code{path == '.'} & \code{package_name} is 32 | not explicitly set, then \code{basename(getwd())} will be used.} 33 | 34 | \item{without_comments}{Boolean. Start project without \code{{golem}} comments} 35 | 36 | \item{project_hook}{A function executed as a hook after project 37 | creation. Can be used to change the default \code{{golem}} structure. 38 | to override the files and content. This function is executed just 39 | after the project is created.} 40 | 41 | \item{with_git}{Boolean. Initialize git repository} 42 | 43 | \item{...}{Arguments passed to the \code{project_hook()} function.} 44 | } 45 | \value{ 46 | The path, invisibly. 47 | } 48 | \description{ 49 | Create a package for a Shiny App using \code{{golem}} 50 | } 51 | \note{ 52 | For compatibility issue, this function turns \code{options(shiny.autoload.r)} 53 | to \code{FALSE}. See https://github.com/ThinkR-open/golem/issues/468 for more background. 54 | } 55 | -------------------------------------------------------------------------------- /man/detach_all_attached.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reload.R 3 | \name{detach_all_attached} 4 | \alias{detach_all_attached} 5 | \title{Detach all attached package} 6 | \usage{ 7 | detach_all_attached() 8 | } 9 | \value{ 10 | TRUE, invisibly. 11 | } 12 | \description{ 13 | Detach all attached package 14 | } 15 | -------------------------------------------------------------------------------- /man/disable_autoload.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/disable_autoload.R 3 | \name{disable_autoload} 4 | \alias{disable_autoload} 5 | \title{Disabling Shiny Autoload of R Scripts} 6 | \usage{ 7 | disable_autoload(golem_wd = get_golem_wd(), pkg) 8 | } 9 | \arguments{ 10 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 11 | 12 | \item{pkg}{Deprecated, please use golem_wd instead} 13 | } 14 | \value{ 15 | The path to the file, invisibly. 16 | } 17 | \description{ 18 | Disabling Shiny Autoload of R Scripts 19 | } 20 | \examples{ 21 | if (interactive()) { 22 | disable_autoload() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /man/document_and_reload.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reload.R 3 | \name{document_and_reload} 4 | \alias{document_and_reload} 5 | \title{Document and reload your package} 6 | \usage{ 7 | document_and_reload( 8 | golem_wd = get_golem_wd(), 9 | roclets = NULL, 10 | load_code = NULL, 11 | clean = FALSE, 12 | export_all = FALSE, 13 | helpers = FALSE, 14 | attach_testthat = FALSE, 15 | ..., 16 | pkg 17 | ) 18 | } 19 | \arguments{ 20 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 21 | 22 | \item{roclets}{Character vector of roclet names to use with package. 23 | The default, \code{NULL}, uses the roxygen \code{roclets} option, 24 | which defaults to \code{c("collate", "namespace", "rd")}.} 25 | 26 | \item{load_code}{A function used to load all the R code in the package 27 | directory. The default, \code{NULL}, uses the strategy defined by 28 | the \code{load} roxygen option, which defaults to \code{\link[roxygen2:load_pkgload]{load_pkgload()}}. 29 | See \link[roxygen2]{load} for more details.} 30 | 31 | \item{clean}{If \code{TRUE}, roxygen will delete all files previously 32 | created by roxygen before running each roclet.} 33 | 34 | \item{export_all}{If \code{TRUE} (the default), export all objects. 35 | If \code{FALSE}, export only the objects that are listed as exports 36 | in the NAMESPACE file.} 37 | 38 | \item{helpers}{if \code{TRUE} loads \pkg{testthat} test helpers.} 39 | 40 | \item{attach_testthat}{If \code{TRUE}, attach \pkg{testthat} to the search path, 41 | which more closely mimics the environment within test files.} 42 | 43 | \item{...}{Other arguments passed to \code{pkgload::load_all()}} 44 | 45 | \item{pkg}{Deprecated, please use golem_wd instead} 46 | } 47 | \value{ 48 | Used for side-effects 49 | } 50 | \description{ 51 | This function calls \code{rstudioapi::documentSaveAll()}, 52 | \code{roxygen2::roxygenise()} and \code{pkgload::load_all()}. 53 | } 54 | -------------------------------------------------------------------------------- /man/favicon.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/use_favicon.R 3 | \name{use_favicon} 4 | \alias{use_favicon} 5 | \alias{remove_favicon} 6 | \alias{favicon} 7 | \title{Add a favicon to your shinyapp} 8 | \usage{ 9 | use_favicon(path, golem_wd = get_golem_wd(), method = "curl", pkg) 10 | 11 | remove_favicon(path = "inst/app/www/favicon.ico") 12 | 13 | favicon( 14 | ico = "favicon", 15 | rel = "shortcut icon", 16 | resources_path = "www", 17 | ext = "ico" 18 | ) 19 | } 20 | \arguments{ 21 | \item{path}{Path to your favicon file (.ico or .png)} 22 | 23 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 24 | 25 | \item{method}{Method to be used for downloading files, 'curl' is default see \code{\link[utils:download.file]{utils::download.file()}}.} 26 | 27 | \item{pkg}{Deprecated, please use golem_wd instead} 28 | 29 | \item{ico}{path to favicon file} 30 | 31 | \item{rel}{rel} 32 | 33 | \item{resources_path}{prefix of the resource path of the app} 34 | 35 | \item{ext}{the extension of the favicon} 36 | } 37 | \value{ 38 | Used for side-effects. 39 | 40 | An HTML tag. 41 | } 42 | \description{ 43 | This function adds the favicon from \code{ico} to your shiny app. 44 | } 45 | \examples{ 46 | if (interactive()) { 47 | use_favicon() 48 | use_favicon(path = "path/to/your/favicon.ico") 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /man/file_creation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add_r_files.R 3 | \name{add_fct} 4 | \alias{add_fct} 5 | \alias{add_utils} 6 | \alias{add_r6} 7 | \title{Add fct_ and utils_ files} 8 | \usage{ 9 | add_fct( 10 | name, 11 | module = NULL, 12 | golem_wd = get_golem_wd(), 13 | open = TRUE, 14 | dir_create = TRUE, 15 | with_test = FALSE, 16 | pkg 17 | ) 18 | 19 | add_utils( 20 | name, 21 | module = NULL, 22 | golem_wd = get_golem_wd(), 23 | open = TRUE, 24 | dir_create = TRUE, 25 | with_test = FALSE, 26 | pkg 27 | ) 28 | 29 | add_r6( 30 | name, 31 | module = NULL, 32 | golem_wd = get_golem_wd(), 33 | open = TRUE, 34 | dir_create = TRUE, 35 | with_test = FALSE, 36 | pkg 37 | ) 38 | } 39 | \arguments{ 40 | \item{name}{The name of the file} 41 | 42 | \item{module}{If not NULL, the file will be module specific 43 | in the naming (you don't need to add the leading \code{mod_}).} 44 | 45 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 46 | 47 | \item{open}{Should the created file be opened?} 48 | 49 | \item{dir_create}{Creates the directory if it doesn't exist, default is \code{TRUE}.} 50 | 51 | \item{with_test}{should the module be created with tests?} 52 | 53 | \item{pkg}{Deprecated, please use golem_wd instead} 54 | } 55 | \value{ 56 | The path to the file, invisibly. 57 | } 58 | \description{ 59 | These functions add files in the R/ folder 60 | that starts either with \code{fct_} (short for function) 61 | or with \code{utils_}. 62 | } 63 | -------------------------------------------------------------------------------- /man/fill_desc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/desc.R 3 | \name{fill_desc} 4 | \alias{fill_desc} 5 | \title{Fill your \code{DESCRIPTION} file} 6 | \usage{ 7 | fill_desc( 8 | pkg_name, 9 | pkg_title, 10 | pkg_description, 11 | authors = person(given = NULL, family = NULL, email = NULL, role = NULL, comment = 12 | NULL), 13 | repo_url = NULL, 14 | pkg_version = "0.0.0.9000", 15 | pkg = get_golem_wd(), 16 | author_first_name = NULL, 17 | author_last_name = NULL, 18 | author_email = NULL, 19 | author_orcid = NULL, 20 | set_options = TRUE 21 | ) 22 | } 23 | \arguments{ 24 | \item{pkg_name}{The name of the package} 25 | 26 | \item{pkg_title}{The title of the package} 27 | 28 | \item{pkg_description}{Description of the package} 29 | 30 | \item{authors}{a character string (or vector) of class person 31 | (see \code{\link[=person]{person()}} for details)} 32 | 33 | \item{repo_url}{URL (if needed)} 34 | 35 | \item{pkg_version}{The version of the package. Default is 0.0.0.9000} 36 | 37 | \item{pkg}{Path to look for the DESCRIPTION. Default is \code{get_golem_wd()}.} 38 | 39 | \item{author_first_name}{to be deprecated: use character for first name via 40 | \code{authors = person(given = "authors_first_name")} instead} 41 | 42 | \item{author_last_name}{to be deprecated: use character for last name via 43 | \code{authors = person(given = "authors_last_name")} instead} 44 | 45 | \item{author_email}{to be deprecated: use character for first name via 46 | \code{authors = person(email = "author_email")} instead} 47 | 48 | \item{author_orcid}{to be deprecated} 49 | 50 | \item{set_options}{logical; the default \code{TRUE} sets all recommended 51 | options but this can be suppressed with \code{FALSE}. For details on the 52 | exact behaviour see the help \code{\link[=set_golem_options]{set_golem_options()}}.} 53 | } 54 | \value{ 55 | The \code{{desc}} object, invisibly. 56 | } 57 | \description{ 58 | Generates a standard \code{DESCRIPTION} file as used in R packages. Also sets 59 | a series of global options inside \code{golem-config.yml} that will be reused 60 | inside \code{{golem}} (see \code{set_options} and \code{\link[=set_golem_options]{set_golem_options()}} for details). 61 | } 62 | -------------------------------------------------------------------------------- /man/get_current_config.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/config.R 3 | \name{get_current_config} 4 | \alias{get_current_config} 5 | \title{Return path to the \code{{golem}} config-file} 6 | \usage{ 7 | get_current_config(path = getwd()) 8 | } 9 | \arguments{ 10 | \item{path}{character string giving the path to start looking for the config; 11 | the usual value is the \code{{golem}}-package top-level directory but a user 12 | supplied config is now supported (see \strong{Details} for how to use this 13 | feature).} 14 | } 15 | \value{ 16 | character string giving the path to the \code{{golem}} config-file 17 | } 18 | \description{ 19 | This function tries to find the current config file, being 20 | either inst/golem-config.yml or the GOLEM_CONFIG_PATH env var 21 | } 22 | \details{ 23 | In most cases this function simply returns the path to the default 24 | golem-config file located under "inst/golem-config.yml". That config comes 25 | in \code{yml}-format, see the \href{https://engineering-shiny.org/golem.html?q=config#golem-config}{Engineering Production-Grade Shiny Apps} 26 | for further details on its format and how to set options therein. 27 | 28 | Advanced app developers may benefit from having an additional user 29 | config-file. This is achieved with setting the GOLEM_CONFIG_PATH env var. 30 | } 31 | -------------------------------------------------------------------------------- /man/get_golem_options.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/with_opt.R 3 | \name{get_golem_options} 4 | \alias{get_golem_options} 5 | \title{Get all or one golem options} 6 | \usage{ 7 | get_golem_options(which = NULL) 8 | } 9 | \arguments{ 10 | \item{which}{NULL (default), or the name of an option} 11 | } 12 | \value{ 13 | The value of the option. 14 | } 15 | \description{ 16 | This function is to be used inside the 17 | server and UI from your app, in order to call the 18 | parameters passed to \code{run_app()}. 19 | } 20 | \examples{ 21 | 22 | # Define and use golem_options 23 | if (interactive()) { 24 | # 1. Pass parameters directly to `run_app` 25 | 26 | run_app( 27 | title = "My Golem App", 28 | content = "something" 29 | ) 30 | 31 | # 2. Get the values 32 | # 2.1 from the UI side 33 | 34 | h1(get_golem_options("title")) 35 | 36 | # 2.2 from the server-side 37 | 38 | output$param <- renderPrint({ 39 | paste("param content = ", get_golem_options("content")) 40 | }) 41 | 42 | output$param_full <- renderPrint({ 43 | get_golem_options() # list of all golem options as a list. 44 | }) 45 | 46 | # 3. If needed, to set default value, edit `run_app` like this : 47 | 48 | run_app <- function( 49 | title = "this", 50 | content = "that", 51 | ... 52 | ) { 53 | with_golem_options( 54 | app = shinyApp( 55 | ui = app_ui, 56 | server = app_server 57 | ), 58 | golem_opts = list( 59 | title = title, 60 | content = content, 61 | ... 62 | ) 63 | ) 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /man/get_sysreqs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_sysreqs.R 3 | \name{get_sysreqs} 4 | \alias{get_sysreqs} 5 | \title{Get system requirements (Deprecated)} 6 | \usage{ 7 | get_sysreqs(packages, quiet = TRUE, batch_n = 30) 8 | } 9 | \arguments{ 10 | \item{packages}{character vector. Packages names.} 11 | 12 | \item{quiet}{Boolean. If \code{TRUE} the function is quiet.} 13 | 14 | \item{batch_n}{numeric. Number of simultaneous packages to ask.} 15 | } 16 | \value{ 17 | A vector of system requirements. 18 | } 19 | \description{ 20 | This function is now deprecated, and was moved to 21 | \code{{dockerfiler}}. 22 | } 23 | -------------------------------------------------------------------------------- /man/golem.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/golem-package.R 3 | \docType{package} 4 | \name{golem} 5 | \alias{golem-package} 6 | \alias{golem} 7 | \title{A package for building Shiny App} 8 | \description{ 9 | Read more about building big shiny apps at \url{https://engineering-shiny.org/}. 10 | } 11 | \seealso{ 12 | Useful links: 13 | \itemize{ 14 | \item \url{https://thinkr-open.github.io/golem/} 15 | \item \url{https://github.com/ThinkR-open/golem} 16 | \item Report bugs at \url{https://github.com/ThinkR-open/golem/issues} 17 | } 18 | 19 | } 20 | \author{ 21 | \strong{Maintainer}: Colin Fay \email{contact@colinfay.me} (\href{https://orcid.org/0000-0001-7343-1846}{ORCID}) 22 | 23 | Authors: 24 | \itemize{ 25 | \item Vincent Guyader \email{vincent@thinkr.fr} (\href{https://orcid.org/0000-0003-0671-9270}{ORCID}) (previous maintainer) 26 | \item Sébastien Rochette \email{sebastien@thinkr.fr} (\href{https://orcid.org/0000-0002-1565-9313}{ORCID}) 27 | \item Cervan Girard \email{cervan@thinkr.fr} (\href{https://orcid.org/0000-0002-4816-4624}{ORCID}) 28 | } 29 | 30 | Other contributors: 31 | \itemize{ 32 | \item Novica Nakov \email{nnovica@gmail.com} [contributor] 33 | \item David Granjon \email{dgranjon@ymail.com} [contributor] 34 | \item Arthur Bréant \email{arthur@thinkr.fr} [contributor] 35 | \item Antoine Languillaume \email{antoine@thinkr.fr} [contributor] 36 | \item Ilya Zarubin \email{zarubin@wiso.uni-koeln.de} [contributor] 37 | \item ThinkR [copyright holder] 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/golem_welcome_page.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/golem_welcome_page.R 3 | \name{golem_welcome_page} 4 | \alias{golem_welcome_page} 5 | \title{Welcome Page} 6 | \usage{ 7 | golem_welcome_page() 8 | } 9 | \value{ 10 | A welcome page for your \code{{golem}} app 11 | } 12 | \description{ 13 | Welcome Page 14 | } 15 | -------------------------------------------------------------------------------- /man/install_dev_deps.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/install_dev_deps.R 3 | \name{install_dev_deps} 4 | \alias{install_dev_deps} 5 | \title{Install \code{{golem}} dev dependencies} 6 | \usage{ 7 | install_dev_deps(dev_deps, force_install = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{dev_deps}{optional character vector of packages to install} 11 | 12 | \item{force_install}{If force_install is TRUE, 13 | then the user is not interactively asked 14 | to install them.} 15 | 16 | \item{...}{further arguments passed to the install function.} 17 | } 18 | \value{ 19 | Used for side-effects 20 | } 21 | \description{ 22 | This function will run rlang::check_installed() on: 23 | \itemize{ 24 | \item {usethis} 25 | \item {pkgload} 26 | \item {dockerfiler} 27 | \item {devtools} 28 | \item {roxygen2} 29 | \item {attachment} 30 | \item {rstudioapi} 31 | \item {fs} 32 | \item {desc} 33 | \item {pkgbuild} 34 | \item {processx} 35 | \item {rsconnect} 36 | \item {testthat} 37 | \item {rstudioapi} 38 | } 39 | } 40 | \examples{ 41 | if (interactive()) { 42 | install_dev_deps() 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /man/is_golem.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/is_golem.R 3 | \name{is_golem} 4 | \alias{is_golem} 5 | \title{Is the directory a golem-based app?} 6 | \usage{ 7 | is_golem(path = getwd()) 8 | } 9 | \arguments{ 10 | \item{path}{Path to the directory to check. 11 | Defaults to the current working directory.} 12 | } 13 | \value{ 14 | A boolean, \code{TRUE} if the directory is a golem-based app, \code{FALSE} else. 15 | } 16 | \description{ 17 | Trying to guess if \code{path} is a golem-based app. 18 | } 19 | \examples{ 20 | is_golem() 21 | } 22 | -------------------------------------------------------------------------------- /man/is_running.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/is_running.R 3 | \name{is_running} 4 | \alias{is_running} 5 | \title{Is the running app a golem app?} 6 | \usage{ 7 | is_running() 8 | } 9 | \value{ 10 | TRUE if the running app is a \code{{golem}} based app, 11 | FALSE otherwise. 12 | } 13 | \description{ 14 | Note that this will return \code{TRUE} only if the application 15 | has been launched with \code{with_golem_options()} 16 | } 17 | \examples{ 18 | is_running() 19 | } 20 | -------------------------------------------------------------------------------- /man/made_dev.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/make_dev.R 3 | \name{cat_dev} 4 | \alias{cat_dev} 5 | \alias{print_dev} 6 | \alias{message_dev} 7 | \alias{warning_dev} 8 | \alias{browser_dev} 9 | \title{Functions already made dev dependent} 10 | \usage{ 11 | cat_dev(...) 12 | 13 | print_dev(...) 14 | 15 | message_dev(...) 16 | 17 | warning_dev(...) 18 | 19 | browser_dev(...) 20 | } 21 | \arguments{ 22 | \item{...}{\R objects (see \sQuote{Details} for the types of objects 23 | allowed).} 24 | } 25 | \value{ 26 | A modified function. 27 | } 28 | \description{ 29 | This functions will be run only if \code{golem::app_dev()} 30 | returns TRUE. 31 | } 32 | -------------------------------------------------------------------------------- /man/maintenance_page.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/maintenance_page.R 3 | \name{maintenance_page} 4 | \alias{maintenance_page} 5 | \title{maintenance_page} 6 | \usage{ 7 | maintenance_page() 8 | } 9 | \value{ 10 | an html_document 11 | } 12 | \description{ 13 | A default html page for maintenance mode 14 | } 15 | \details{ 16 | see the vignette \code{vignette("f_extending_golem", package = "golem")} for details. 17 | } 18 | -------------------------------------------------------------------------------- /man/make_dev.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/make_dev.R 3 | \name{make_dev} 4 | \alias{make_dev} 5 | \title{Make a function dependent to dev mode} 6 | \usage{ 7 | make_dev(fun) 8 | } 9 | \arguments{ 10 | \item{fun}{A function} 11 | } 12 | \value{ 13 | Used for side-effects 14 | } 15 | \description{ 16 | The function returned will be run only if \code{golem::app_dev()} 17 | returns TRUE. 18 | } 19 | -------------------------------------------------------------------------------- /man/module_template.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modules_fn.R 3 | \name{module_template} 4 | \alias{module_template} 5 | \title{Golem Module Template Function} 6 | \usage{ 7 | module_template(name, path, export, ph_ui = " ", ph_server = " ", ...) 8 | } 9 | \arguments{ 10 | \item{name}{The name of the module.} 11 | 12 | \item{path}{The path to the R script where the module will be written. 13 | Note that this path will not be set by the user but via 14 | \code{add_module()}.} 15 | 16 | \item{export}{Should the module be exported? Default is \code{FALSE}.} 17 | 18 | \item{ph_ui, ph_server}{Texts to insert inside the modules UI and server. 19 | For advanced use.} 20 | 21 | \item{...}{Arguments to be passed to the \code{module_template} function.} 22 | } 23 | \value{ 24 | Used for side effect 25 | } 26 | \description{ 27 | Module template can be used to extend golem module creation 28 | mechanism with your own template, so that you can be even more 29 | productive when building your \code{{shiny}} app. 30 | Module template functions do not aim at being called as is by 31 | users, but to be passed as an argument to the \code{add_module()} 32 | function. 33 | } 34 | \details{ 35 | Module template functions are a way to define your own template 36 | function for module. A template function that can take the following 37 | arguments to be passed from \code{add_module()}: 38 | \itemize{ 39 | \item name: the name of the module 40 | \item path: the path to the file in R/ 41 | \item export: a TRUE/FALSE set by the \code{export} param of \code{add_module()} 42 | } 43 | 44 | If you want your function to ignore these parameters, set \code{...} as the 45 | last argument of your function, then these will be ignored. See the examples 46 | section of this help. 47 | } 48 | \examples{ 49 | 50 | if (interactive()) { 51 | my_tmpl <- function(name, path, ...) { 52 | # Define a template that write to the 53 | # module file 54 | write(name, path) 55 | } 56 | golem::add_module(name = "custom", module_template = my_tmpl) 57 | 58 | my_other_tmpl <- function(name, path, ...) { 59 | # Copy and paste a file from somewhere 60 | file.copy(..., path) 61 | } 62 | golem::add_module(name = "custom", module_template = my_other_tmpl) 63 | } 64 | } 65 | \seealso{ 66 | \code{\link[=add_module]{add_module()}} 67 | } 68 | -------------------------------------------------------------------------------- /man/pkg_tools.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pkg_tools.R 3 | \name{pkg_name} 4 | \alias{pkg_name} 5 | \alias{pkg_version} 6 | \alias{pkg_path} 7 | \title{Package tools} 8 | \usage{ 9 | pkg_name(golem_wd = get_golem_wd(), path) 10 | 11 | pkg_version(golem_wd = get_golem_wd(), path) 12 | 13 | pkg_path() 14 | } 15 | \arguments{ 16 | \item{golem_wd}{Path to use to read the DESCRIPTION} 17 | 18 | \item{path}{Deprecated, use golem_wd instead} 19 | } 20 | \value{ 21 | The value of the entry in the DESCRIPTION file 22 | } 23 | \description{ 24 | These are functions to help you navigate 25 | inside your project while developing 26 | } 27 | -------------------------------------------------------------------------------- /man/prod.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/make_dev.R 3 | \name{app_prod} 4 | \alias{app_prod} 5 | \alias{app_dev} 6 | \title{Is the app in dev mode or prod mode?} 7 | \usage{ 8 | app_prod() 9 | 10 | app_dev() 11 | } 12 | \value{ 13 | \code{TRUE} or \code{FALSE} depending on the status of \code{getOption( "golem.app.prod")} 14 | } 15 | \description{ 16 | Is the app in dev mode or prod mode? 17 | } 18 | -------------------------------------------------------------------------------- /man/project_hook.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/templates.R 3 | \name{project_hook} 4 | \alias{project_hook} 5 | \title{Project Hook} 6 | \usage{ 7 | project_hook(path, package_name, ...) 8 | } 9 | \arguments{ 10 | \item{path}{Name of the folder to create the package in. 11 | This will also be used as the package name.} 12 | 13 | \item{package_name}{Package name to use. By default, \code{{golem}} uses 14 | \code{basename(path)}. If \code{path == '.'} & \code{package_name} is 15 | not explicitly set, then \code{basename(getwd())} will be used.} 16 | 17 | \item{...}{Arguments passed from \code{create_golem()}, unused in the default 18 | function.} 19 | } 20 | \value{ 21 | Used for side effects 22 | } 23 | \description{ 24 | Project hooks allow to define a function run just after \code{{golem}} 25 | project creation. 26 | } 27 | \examples{ 28 | if (interactive()) { 29 | my_proj <- function(...) { 30 | unlink("dev/", TRUE, TRUE) 31 | } 32 | create_golem("ici", project_template = my_proj) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /man/rstudio_deploy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add_rstudio_files.R 3 | \name{add_positconnect_file} 4 | \alias{add_positconnect_file} 5 | \alias{add_rconnect_file} 6 | \alias{add_rstudioconnect_file} 7 | \alias{add_shinyappsio_file} 8 | \alias{add_shinyserver_file} 9 | \alias{add_rscignore_file} 10 | \title{Add an \code{app.R} at the root of your package to deploy on RStudio Connect} 11 | \usage{ 12 | add_positconnect_file(golem_wd = get_golem_wd(), open = TRUE, pkg) 13 | 14 | add_rstudioconnect_file(golem_wd = get_golem_wd(), open = TRUE, pkg) 15 | 16 | add_shinyappsio_file(golem_wd = get_golem_wd(), open = TRUE, pkg) 17 | 18 | add_shinyserver_file(golem_wd = get_golem_wd(), open = TRUE, pkg) 19 | 20 | add_rscignore_file(golem_wd = get_golem_wd(), open = TRUE, pkg) 21 | } 22 | \arguments{ 23 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 24 | 25 | \item{open}{Should the created file be opened?} 26 | 27 | \item{pkg}{Deprecated, please use golem_wd instead} 28 | } 29 | \value{ 30 | Side-effect functions for file creation returning the path to the 31 | file, invisibly. 32 | } 33 | \description{ 34 | Additionally, adds a \code{.rscignore} at the root of the \code{{golem}} project if the 35 | \code{rsconnect} package version is \verb{>= 0.8.25}. 36 | } 37 | \note{ 38 | In previous versions, this function was called add_rconnect_file. 39 | 40 | \code{add_rstudioconnect_file} is now deprecated; replace by \code{\link[=add_positconnect_file]{add_positconnect_file()}}. 41 | } 42 | \section{List of excluded files in \code{.rscignore}}{ 43 | 44 | \itemize{ 45 | \item .here 46 | \item CODE_OF_CONDUCT.md 47 | \item LICENSE\{.md\} 48 | \item LICENCE\{.md\} 49 | \item NEWS\{.md\} 50 | \item README\{.md,.Rmd,.HTML\} 51 | \item dev 52 | \item man 53 | \item tests 54 | \item vignettes 55 | } 56 | } 57 | 58 | \examples{ 59 | # Add a file for Connect 60 | if (interactive()) { 61 | add_positconnect_file() 62 | } 63 | # Add a file for Shiny Server 64 | if (interactive()) { 65 | add_shinyserver_file() 66 | } 67 | # Add a file for Shinyapps.io 68 | if (interactive()) { 69 | add_shinyappsio_file() 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /man/run_dev.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/run_dev.R 3 | \name{run_dev} 4 | \alias{run_dev} 5 | \title{Run the \code{dev/run_dev.R} file} 6 | \usage{ 7 | run_dev( 8 | file = "dev/run_dev.R", 9 | golem_wd = get_golem_wd(), 10 | save_all = TRUE, 11 | install_required_packages = TRUE, 12 | pkg 13 | ) 14 | } 15 | \arguments{ 16 | \item{file}{String with (relative) file path to a \code{run_dev.R}-file} 17 | 18 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 19 | 20 | \item{save_all}{Boolean; if \code{TRUE} saves all open files before sourcing 21 | \code{file}} 22 | 23 | \item{install_required_packages}{Boolean; if \code{TRUE} install the packages 24 | used in \code{run_dev.R}-file} 25 | 26 | \item{pkg}{Deprecated, please use golem_wd instead} 27 | } 28 | \value{ 29 | pure side-effect function; returns invisibly 30 | } 31 | \description{ 32 | The default \code{file="dev/run_dev.R"} launches your \code{{golem}} app with a bunch 33 | of useful options. The file content can be customized and \code{file}-name and 34 | path changed as long as the argument combination of \code{file} and \code{pkg} are 35 | supplied correctly: the \code{file}-path is a relative path to a \code{{golem}}-package 36 | root \code{pkg}. An error is thrown if \code{pkg/file} cannot be found. 37 | } 38 | \details{ 39 | The function \code{run_dev()} is typically used to launch a shiny app by sourcing 40 | the content of an appropriate \code{run_dev}-file. Carefully read the content of 41 | \code{dev/run_dev.R} when creating your custom \code{run_dev}-file. It has already 42 | many useful settings including a switch between production/development, 43 | reloading the package in a clean \code{R} environment before running the app etc. 44 | } 45 | -------------------------------------------------------------------------------- /man/sanity_check.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sanity_check.R 3 | \name{sanity_check} 4 | \alias{sanity_check} 5 | \title{Sanity check for R files in the project} 6 | \usage{ 7 | sanity_check(golem_wd = get_golem_wd(), pkg) 8 | } 9 | \arguments{ 10 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 11 | 12 | \item{pkg}{Deprecated, please use golem_wd instead} 13 | } 14 | \value{ 15 | A DataFrame if any of the words has been found. 16 | } 17 | \description{ 18 | This function is used check for any `browser()`` or commented 19 | #TODO / #TOFIX / #BUG in the code 20 | } 21 | -------------------------------------------------------------------------------- /man/template.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/templates.R 3 | \name{js_handler_template} 4 | \alias{js_handler_template} 5 | \alias{js_template} 6 | \alias{css_template} 7 | \alias{sass_template} 8 | \alias{empty_template} 9 | \title{Golem's default custom templates} 10 | \usage{ 11 | js_handler_template(path, name = "fun", code = " ") 12 | 13 | js_template(path, code = " ") 14 | 15 | css_template(path, code = " ") 16 | 17 | sass_template(path, code = " ") 18 | 19 | empty_template(path, code = " ") 20 | } 21 | \arguments{ 22 | \item{path}{The path to the JS script where this template will be written.} 23 | 24 | \item{name}{Shiny's custom handler name.} 25 | 26 | \item{code}{JavaScript code to be written in the function.} 27 | } 28 | \value{ 29 | Used for side effect 30 | } 31 | \description{ 32 | These functions do not aim at being called as is by 33 | users, but to be passed as an argument to the \code{add_js_handler()} 34 | function. 35 | } 36 | \seealso{ 37 | \code{\link[=add_js_handler]{add_js_handler()}} 38 | } 39 | -------------------------------------------------------------------------------- /man/testhelpers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_helpers.R 3 | \name{expect_shinytag} 4 | \alias{expect_shinytag} 5 | \alias{expect_shinytaglist} 6 | \alias{expect_html_equal} 7 | \alias{expect_running} 8 | \title{Test helpers} 9 | \usage{ 10 | expect_shinytag(object) 11 | 12 | expect_shinytaglist(object) 13 | 14 | expect_html_equal(ui, html, ...) 15 | 16 | expect_running(sleep, R_path = NULL) 17 | } 18 | \arguments{ 19 | \item{object}{the object to test} 20 | 21 | \item{ui}{output of an UI function} 22 | 23 | \item{html}{deprecated} 24 | 25 | \item{...}{arguments passed to \code{testthat::expect_snapshot()}} 26 | 27 | \item{sleep}{number of seconds} 28 | 29 | \item{R_path}{path to R. If NULL, the function will try to guess where R is.} 30 | } 31 | \value{ 32 | A testthat result. 33 | } 34 | \description{ 35 | These functions are designed to be used inside the tests 36 | in your Shiny app package. 37 | } 38 | -------------------------------------------------------------------------------- /man/use_module_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modules_fn.R 3 | \name{use_module_test} 4 | \alias{use_module_test} 5 | \title{Add a test file for a module} 6 | \usage{ 7 | use_module_test(name, golem_wd = get_golem_wd(), open = TRUE, pkg) 8 | } 9 | \arguments{ 10 | \item{name}{The name of the module.} 11 | 12 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 13 | 14 | \item{open}{Should the created file be opened?} 15 | 16 | \item{pkg}{Deprecated, please use golem_wd instead} 17 | } 18 | \value{ 19 | Used for side effect. Returns the path invisibly. 20 | } 21 | \description{ 22 | Add a test file for in module, with the new testServer structure. 23 | } 24 | -------------------------------------------------------------------------------- /man/use_readme_rmd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/use_readme.R 3 | \name{use_readme_rmd} 4 | \alias{use_readme_rmd} 5 | \title{Generate a README.Rmd} 6 | \usage{ 7 | use_readme_rmd( 8 | open = rlang::is_interactive(), 9 | pkg_name = golem::get_golem_name(), 10 | overwrite = FALSE, 11 | golem_wd = golem::get_golem_wd(), 12 | pkg 13 | ) 14 | } 15 | \arguments{ 16 | \item{open}{Open the newly created file for editing? Happens in RStudio, if 17 | applicable, or via \code{\link[utils:file.edit]{utils::file.edit()}} otherwise.} 18 | 19 | \item{pkg_name}{The name of the package} 20 | 21 | \item{overwrite}{an optional \code{logical} flag; if \code{TRUE}, overwrite 22 | existing \code{README.Rmd}, else throws an error if \code{README.Rmd} exists} 23 | 24 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 25 | 26 | \item{pkg}{Deprecated, please use golem_wd instead} 27 | } 28 | \value{ 29 | pure side-effect function that generates template \code{README.Rmd} 30 | } 31 | \description{ 32 | Generate a README.Rmd 33 | } 34 | -------------------------------------------------------------------------------- /man/use_recommended.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/use_recommended.R 3 | \name{use_recommended_deps} 4 | \alias{use_recommended_deps} 5 | \alias{use_recommended_tests} 6 | \title{Add recommended elements} 7 | \usage{ 8 | use_recommended_deps( 9 | pkg = get_golem_wd(), 10 | recommended = c("shiny", "DT", "attempt", "glue", "htmltools", "golem") 11 | ) 12 | 13 | use_recommended_tests( 14 | golem_wd = get_golem_wd(), 15 | spellcheck = TRUE, 16 | vignettes = TRUE, 17 | lang = "en-US", 18 | error = FALSE, 19 | pkg 20 | ) 21 | } 22 | \arguments{ 23 | \item{pkg}{Deprecated, please use golem_wd instead} 24 | 25 | \item{recommended}{A vector of recommended packages.} 26 | 27 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 28 | 29 | \item{spellcheck}{Whether or not to use a spellcheck test.} 30 | 31 | \item{vignettes}{Logical, \code{TRUE} to spell check all \code{rmd} and \code{rnw} files in 32 | the \verb{vignettes/} folder.} 33 | 34 | \item{lang}{Preferred spelling language. Usually either \code{"en-US"} or 35 | \code{"en-GB"}.} 36 | 37 | \item{error}{Logical, indicating whether the unit test should fail if 38 | spelling errors are found. Defaults to \code{FALSE}, which does not error, but 39 | prints potential spelling errors} 40 | } 41 | \value{ 42 | Used for side-effects. 43 | } 44 | \description{ 45 | \describe{ 46 | \item{use_recommended_deps}{Adds \code{shiny}, \code{DT}, \code{attempt}, \code{glue}, \code{golem}, \code{htmltools} to dependencies} 47 | \item{use_recommended_tests}{Adds a test folder and copy the golem tests} 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /man/utils_files.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/use_utils.R 3 | \name{use_utils_ui} 4 | \alias{use_utils_ui} 5 | \alias{use_utils_test_ui} 6 | \alias{use_utils_server} 7 | \alias{use_utils_test_server} 8 | \title{Use the utils files} 9 | \usage{ 10 | use_utils_ui(golem_wd = get_golem_wd(), with_test = FALSE, pkg) 11 | 12 | use_utils_test_ui(golem_wd = get_golem_wd(), pkg) 13 | 14 | use_utils_server(golem_wd = get_golem_wd(), with_test = FALSE, pkg) 15 | 16 | use_utils_test_ui(golem_wd = get_golem_wd(), pkg) 17 | 18 | use_utils_test_server(golem_wd = get_golem_wd(), pkg) 19 | } 20 | \arguments{ 21 | \item{golem_wd}{Path to the root of the package. Default is \code{get_golem_wd()}.} 22 | 23 | \item{with_test}{should the module be created with tests?} 24 | 25 | \item{pkg}{Deprecated, please use golem_wd instead} 26 | } 27 | \value{ 28 | Used for side-effects. 29 | } 30 | \description{ 31 | \describe{ 32 | \item{use_utils_ui}{Copies the golem_utils_ui.R to the R folder.} 33 | \item{use_utils_server}{Copies the golem_utils_server.R to the R folder.} 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /man/with_golem_options.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/with_opt.R 3 | \name{with_golem_options} 4 | \alias{with_golem_options} 5 | \title{Add Golem options to a Shiny App} 6 | \usage{ 7 | with_golem_options( 8 | app, 9 | golem_opts, 10 | maintenance_page = golem::maintenance_page, 11 | print = FALSE 12 | ) 13 | } 14 | \arguments{ 15 | \item{app}{the app object.} 16 | 17 | \item{golem_opts}{A list of options to be added to the app} 18 | 19 | \item{maintenance_page}{an html_document or a shiny tag list. Default is golem template.} 20 | 21 | \item{print}{Whether or not to print the app. Default is to \code{FALSE}, which 22 | should be what you need 99.99\% of the time. In case you need to 23 | actively print() the app object, you can set it to \code{TRUE}.} 24 | } 25 | \value{ 26 | a shiny.appObj object 27 | } 28 | \description{ 29 | You'll probably never have to write this function 30 | as it is included in the golem template created on 31 | launch. 32 | } 33 | -------------------------------------------------------------------------------- /pkgdown/_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://thinkr-open.github.io/golem/ 2 | 3 | template: 4 | bootstrap: 5 5 | theme: github-dark 6 | bslib: 7 | pkgdown-nav-height: 100px 8 | primary: "#7176b8" 9 | info: "#f15521" 10 | bg: "#fafafa" 11 | fg: "#38424f" 12 | navbar-brand-font-size: 2rem 13 | navbar-light-brand-color: "#fafafa" 14 | navbar-light-brand-hover-color: "#fafafa" 15 | navbar-light-color: "#fafafa" 16 | navbar-light-hover-color: "#fafafa" 17 | navbar-light-toggler-border-color: "#fafafa" 18 | link-color: "#f15521" 19 | link-decoration: underline dotted 20 | dropdown-link-active-bg: "#f15521" 21 | code-bg: "#f155212b" 22 | base_font: { google: "Rubik" } 23 | heading_font: { google: "Rubik" } 24 | 25 | navbar: 26 | bg: info 27 | type: light 28 | structure: 29 | left: [reference, articles, resources, news] 30 | right: [github, golemverse] 31 | components: 32 | contribute: 33 | text: Contribute 34 | href: articles/contribute.html 35 | golemverse: 36 | icon: fas fa-toolbox 37 | href: https://golemverse.org/ 38 | aria-label: Golemverse 39 | resources: 40 | text: Resources 41 | href: articles/resources.html 42 | 43 | footer: 44 | structure: 45 | left: thinkr 46 | right: [golemverse] 47 | components: 48 | thinkr: © ThinkR - A French company of R experts 49 | golemverse: Explore the Golemverse 50 | -------------------------------------------------------------------------------- /pkgdown/extra.scss: -------------------------------------------------------------------------------- 1 | .navbar-dark input[type="search"] { 2 | background-color: var(--bs-body-bg); 3 | color: var(--bs-body-color); 4 | } 5 | 6 | .navbar-light .navbar-nav .active > .nav-link { 7 | color: var(--bs-body-bg); 8 | background: var(--bs-info); 9 | } 10 | 11 | .navbar-nav .nav-link.active, 12 | .navbar-nav .nav-link.show { 13 | color: var(--bs-body-bg); 14 | background: var(--bs-info); 15 | } 16 | 17 | .text-muted { 18 | color: var(--bs-body-bg) !important; 19 | background-color: #7176b83d; 20 | padding: 1.5px 2px; 21 | border-radius: 4px; 22 | } 23 | 24 | /* ---- Callouts ---- */ 25 | .callout { 26 | border: 1px solid var(--bs-primary); 27 | padding: 1rem 2rem; 28 | margin: 1rem 0; 29 | border-radius: var(--bs-border-radius); 30 | display: grid; 31 | grid-template-columns: auto 1fr; 32 | align-items: center; 33 | gap: 3rem; 34 | background: #7176b817; 35 | 36 | p { 37 | margin: 10px 0; 38 | } 39 | } 40 | 41 | @mixin callout($content, $color) { 42 | &::before { 43 | content: $content; 44 | font-weight: bold; 45 | font-size: 1.25rem; 46 | font-style: italic; 47 | font-family: serif; 48 | border-radius: 50%; 49 | color: var(--bs-body-bg); 50 | background-color: $color; 51 | width: 2rem; 52 | height: 2rem; 53 | display: inline-flex; 54 | align-items: center; 55 | justify-content: center; 56 | } 57 | } 58 | 59 | .callout.callout-note { 60 | @include callout("i", var(--bs-primary)); 61 | } 62 | 63 | .callout.callout-danger { 64 | @include callout("!", var(--bs-warning)); 65 | } 66 | 67 | strong { 68 | color: var(--bs-primary); 69 | text-decoration: underline; 70 | } 71 | -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if (requireNamespace("spelling", quietly = TRUE)) { 2 | spelling::spell_check_test( 3 | vignettes = TRUE, 4 | error = FALSE, 5 | skip_on_cran = TRUE 6 | ) 7 | } 8 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview 7 | # * https://testthat.r-lib.org/articles/special-files.html 8 | 9 | library(testthat) 10 | library(golem) 11 | 12 | test_check("golem") 13 | -------------------------------------------------------------------------------- /tests/testthat/Dockerfile.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/golem/3a5c7a46351f7fb3f8ba9d2e6b22a92c13d282c2/tests/testthat/Dockerfile.RDS -------------------------------------------------------------------------------- /tests/testthat/_snaps/after_creation_msg.md: -------------------------------------------------------------------------------- 1 | # after_creation_msg works 2 | 3 | Code 4 | after_creation_message_generic("mypkg", "inst/app/www", "myjs") 5 | Output 6 | * File myjs created 7 | Code 8 | after_creation_message_js("mypkg", "inst/app/www", "myjs") 9 | after_creation_message_css("mypkg", "inst/app/www", "mycss") 10 | after_creation_message_sass("mypkg", "inst/app/www", "mysass") 11 | after_creation_message_html_template("mypkg", "inst/app/www", "myhtml") 12 | Output 13 | 14 | To use this html file as a template, add the following code in your UI: 15 | htmlTemplate( 16 | app_sys("app/www/myhtml.html"), 17 | body = tagList() 18 | # add here other template arguments 19 | ) 20 | Code 21 | testthat::with_mocked_bindings(fs_path_abs = paste, { 22 | after_creation_message_any_file("mypkg", "inst/app/www", "myhtml") 23 | }) 24 | Output 25 | 26 | File downloaded at inst/app/www/myhtml 27 | Code 28 | file_created_dance("inst/app/www", after_creation_message_sass, "mypkg", 29 | "inst/app/www", "mysass", open_file = FALSE) 30 | Output 31 | v File created at inst/app/www 32 | * Go to inst/app/www 33 | Code 34 | file_already_there_dance("inst/app/www", open_file = FALSE) 35 | Output 36 | v File already exists. 37 | * Go to inst/app/www 38 | 39 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/browser_button.md: -------------------------------------------------------------------------------- 1 | # browser_button works 2 | 3 | Code 4 | browser_button() 5 | Output 6 | -- To be copied in your UI ----------------------------------------------------- 7 | actionButton("browser", "browser"), 8 | tags$script("$('#browser').hide();") 9 | 10 | -- To be copied in your server ------------------------------------------------- 11 | observeEvent(input$browser,{ 12 | browser() 13 | }) 14 | 15 | By default, this button will be hidden. 16 | To show it, open your web browser JavaScript console 17 | And run $('#browser').show(); 18 | 19 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/cats.md: -------------------------------------------------------------------------------- 1 | # cats works 2 | 3 | Code 4 | cat_green_tick("File downloaded at /tmp") 5 | Output 6 | v File downloaded at /tmp 7 | Code 8 | cat_red_bullet("File not added (needs a valid directory)") 9 | Output 10 | * File not added (needs a valid directory) 11 | Code 12 | cat_info("File copied to /tmp") 13 | Output 14 | > File copied to /tmp 15 | Code 16 | cat_exists("/tmp") 17 | Output 18 | * [Skipped] tmp already exists. 19 | > If you want replace it, remove the tmp file first. 20 | Code 21 | cat_dir_necessary() 22 | Output 23 | * File not added (needs a valid directory) 24 | Code 25 | cat_start_download() 26 | Output 27 | 28 | Initiating file download 29 | Code 30 | cat_downloaded("/tmp") 31 | Output 32 | v File downloaded at /tmp 33 | Code 34 | cat_start_copy() 35 | Output 36 | 37 | Copying file 38 | Code 39 | cat_copied("/tmp") 40 | Output 41 | v File copied to /tmp 42 | Code 43 | cat_created("/tmp") 44 | Output 45 | v File created at /tmp 46 | Code 47 | cat_automatically_linked() 48 | Output 49 | v File automatically linked in `golem_add_external_resources()`. 50 | 51 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/config.md: -------------------------------------------------------------------------------- 1 | # ask_golem_creation_upon_config works 2 | 3 | Code 4 | ask_golem_creation_upon_config("/home/golem") 5 | Output 6 | [1] "The golem file doesn't exist.\nIt's possible that you might not be in a {golem} based project.\nDo you want to create the {golem} files?" 7 | 8 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/use_files_external_tools.md: -------------------------------------------------------------------------------- 1 | # check_url_has_the_correct_extension(url, where) works 2 | 3 | Code 4 | check_url_has_the_correct_extension("https://www.google.com", "js") 5 | Condition 6 | Error: 7 | ! File not added (URL must end with .js extension) 8 | 9 | # download_external(url, where) works 10 | 11 | Code 12 | testthat::with_mocked_bindings(utils_download_file = function(url, where) { 13 | print(url) 14 | print(where) 15 | }, { 16 | download_external("https://www.google.com", "inst/app/www/google.html") 17 | }) 18 | Output 19 | 20 | Initiating file download 21 | [1] "https://www.google.com" 22 | [1] "inst/app/www/google.html" 23 | v File downloaded at inst/app/www/google.html 24 | 25 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/use_files_internal_tools.md: -------------------------------------------------------------------------------- 1 | # copy_internal_file works 2 | 3 | Code 4 | testthat::with_mocked_bindings(copy_internal_file = function(path, where) { 5 | print(path) 6 | print(where) 7 | }, { 8 | copy_internal_file("~/here/this.css", "inst/app/this.css") 9 | }) 10 | Output 11 | [1] "~/here/this.css" 12 | [1] "inst/app/this.css" 13 | 14 | # check_url_has_the_correct_extension(url, where) works 15 | 16 | Code 17 | check_file_has_the_correct_extension("https://www.google.com", "js") 18 | Condition 19 | Error: 20 | ! File not added (URL must end with .js) 21 | 22 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/use_files_shared_tools.md: -------------------------------------------------------------------------------- 1 | # check_directory_exists works as expected 2 | 3 | Code 4 | check_directory_exists("inst/app/www") 5 | Condition 6 | Error: 7 | ! The inst/app/www directory is required but does not exist. 8 | 9 | You can create it with: dir.create('inst/app/www', recursive = TRUE) 10 | 11 | -------------------------------------------------------------------------------- /tests/testthat/browser_button.test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/golem/3a5c7a46351f7fb3f8ba9d2e6b22a92c13d282c2/tests/testthat/browser_button.test -------------------------------------------------------------------------------- /tests/testthat/dockerfiler_dock_from_renv_socle.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/golem/3a5c7a46351f7fb3f8ba9d2e6b22a92c13d282c2/tests/testthat/dockerfiler_dock_from_renv_socle.RDS -------------------------------------------------------------------------------- /tests/testthat/test-add_dockerfiles.R: -------------------------------------------------------------------------------- 1 | test_that("talk_once", { 2 | once_sum <- talk_once(sum, "Hey there") 3 | expect_output( 4 | once_sum(), 5 | "Hey there" 6 | ) 7 | expect_silent( 8 | once_sum() 9 | ) 10 | }) 11 | 12 | test_that("add_dockerfile works", { 13 | skip_on_cran() 14 | skip_if_not_installed("dockerfiler", "0.2.3") 15 | dummy_golem <- create_dummy_golem() 16 | 17 | testthat::with_mocked_bindings( 18 | dockerfiler_dock_from_desc = function(...) { 19 | return(readRDS("Dockerfile.RDS")) 20 | }, 21 | usethis_use_build_ignore = function(...) { 22 | return(NULL) 23 | }, 24 | { 25 | withr::with_options( 26 | c("usethis.quiet" = TRUE), 27 | { 28 | dockerfile_with_add_dockerfile <- add_dockerfile( 29 | path = file.path( 30 | dummy_golem, 31 | "DESCRIPTION" 32 | ), 33 | golem_wd = dummy_golem, 34 | output = file.path( 35 | dummy_golem, 36 | "Dockerfile_add_dockerfile" 37 | ), 38 | open = FALSE 39 | ) 40 | dockerfile_with_add_dockerfile_shinyproxy <- add_dockerfile_shinyproxy( 41 | path = file.path( 42 | dummy_golem, 43 | "DESCRIPTION" 44 | ), 45 | golem_wd = dummy_golem, 46 | output = file.path( 47 | dummy_golem, 48 | "Dockerfile_add_dockerfile_shinyproxy" 49 | ), 50 | open = FALSE 51 | ) 52 | 53 | dockerfile_with_add_dockerfile_heroku <- add_dockerfile_heroku( 54 | path = file.path( 55 | dummy_golem, 56 | "DESCRIPTION" 57 | ), 58 | golem_wd = dummy_golem, 59 | , 60 | output = file.path( 61 | dummy_golem, 62 | "Dockerfile_add_dockerfile_heroku" 63 | ), 64 | open = FALSE 65 | ) 66 | } 67 | ) 68 | } 69 | ) 70 | expect_true( 71 | inherits( 72 | dockerfile_with_add_dockerfile, 73 | "Dockerfile" 74 | ) 75 | ) 76 | expect_true( 77 | inherits( 78 | dockerfile_with_add_dockerfile_shinyproxy, 79 | "Dockerfile" 80 | ) 81 | ) 82 | expect_true( 83 | inherits( 84 | dockerfile_with_add_dockerfile_heroku, 85 | "Dockerfile" 86 | ) 87 | ) 88 | unlink(dummy_golem, TRUE, TRUE) 89 | }) 90 | -------------------------------------------------------------------------------- /tests/testthat/test-add_dockerfiles_renv.R: -------------------------------------------------------------------------------- 1 | test_that("add_dockerfile_with_renv_ works", { 2 | skip_on_cran() 3 | skip_if_not_installed("renv") 4 | skip_if_not_installed("dockerfiler", "0.2.3") 5 | skip_if_not_installed("attachment", "0.2.5") 6 | dummy_golem <- create_dummy_golem() 7 | testthat::with_mocked_bindings( 8 | attachment_create_renv_for_prod = function(...) { 9 | return(normalizePath("renv.lock.prod")) 10 | }, 11 | dockerfiler_dock_from_renv = function(...) { 12 | return( 13 | readRDS( 14 | "dockerfiler_dock_from_renv_socle.RDS" 15 | ) 16 | ) 17 | }, 18 | { 19 | withr::with_options( 20 | c("usethis.quiet" = TRUE), 21 | { 22 | dockerfile_with_renv <- add_dockerfile_with_renv_( 23 | golem_wd = dummy_golem, 24 | lockfile = "renv.lock.prod", 25 | pkgbuild_quiet = TRUE 26 | ) 27 | 28 | dockerfile_with_renv_output <- add_dockerfile_with_renv( 29 | golem_wd = dummy_golem, 30 | lockfile = "renv.lock.prod", 31 | open = FALSE 32 | ) 33 | dockerfile_with_renv_shinyproxy_output <- add_dockerfile_with_renv_shinyproxy( 34 | golem_wd = dummy_golem, 35 | lockfile = "renv.lock.prod", 36 | open = FALSE 37 | ) 38 | dockerfile_with_renv_heroku_output <- add_dockerfile_with_renv_heroku( 39 | golem_wd = dummy_golem, 40 | lockfile = "renv.lock.prod", 41 | open = FALSE 42 | ) 43 | } 44 | ) 45 | } 46 | ) 47 | expect_true( 48 | inherits( 49 | dockerfile_with_renv, 50 | "Dockerfile" 51 | ) 52 | ) 53 | expect_true( 54 | file.exists( 55 | dockerfile_with_renv_output 56 | ) 57 | ) 58 | expect_true( 59 | file.exists( 60 | dockerfile_with_renv_shinyproxy_output 61 | ) 62 | ) 63 | expect_true( 64 | file.exists( 65 | dockerfile_with_renv_heroku_output 66 | ) 67 | ) 68 | unlink( 69 | dummy_golem, 70 | TRUE, 71 | TRUE 72 | ) 73 | }) 74 | -------------------------------------------------------------------------------- /tests/testthat/test-add_r_files.R: -------------------------------------------------------------------------------- 1 | test_that("add_fct and add_utils", { 2 | testthat::with_mocked_bindings( 3 | # This is just to bypass usethis_use_test 4 | usethis_use_test = function(name, ...) { 5 | file.create( 6 | file.path( 7 | sprintf( 8 | "tests/testthat/test-%s.R", 9 | name 10 | ) 11 | ) 12 | ) 13 | }, 14 | { 15 | run_quietly_in_a_dummy_golem({ 16 | add_fct( 17 | "ui", 18 | open = FALSE, 19 | with_test = TRUE 20 | ) 21 | add_utils( 22 | "ui", 23 | open = FALSE, 24 | with_test = TRUE 25 | ) 26 | 27 | add_module( 28 | "rand", 29 | open = FALSE, 30 | with_test = TRUE 31 | ) 32 | add_fct( 33 | "ui", 34 | "rand", 35 | open = FALSE 36 | ) 37 | add_utils( 38 | "ui", 39 | "rand", 40 | open = FALSE 41 | ) 42 | expect_exists( 43 | file.path( 44 | "R", 45 | "fct_ui.R" 46 | ) 47 | ) 48 | expect_exists( 49 | file.path( 50 | "R", 51 | "utils_ui.R" 52 | ) 53 | ) 54 | expect_exists( 55 | file.path( 56 | "tests/testthat/test-utils_ui.R" 57 | ) 58 | ) 59 | expect_exists( 60 | file.path( 61 | "tests/testthat/test-fct_ui.R" 62 | ) 63 | ) 64 | 65 | expect_error( 66 | add_fct(c("a", "b")), 67 | ) 68 | expect_error( 69 | add_utils(c("a", "b")), 70 | ) 71 | 72 | expect_error( 73 | add_module(c("a", "b")), 74 | ) 75 | 76 | # If module not yet created an error is thrown 77 | expect_error( 78 | add_fct( 79 | "ui", 80 | module = "notyetcreated", 81 | open = FALSE 82 | ), 83 | regexp = "The module 'notyetcreated' does not exist." 84 | ) 85 | expect_error( 86 | add_utils( 87 | "ui", 88 | module = "notyetcreated", 89 | open = FALSE 90 | ), 91 | regexp = "The module 'notyetcreated' does not exist." 92 | ) 93 | }) 94 | } 95 | ) 96 | }) 97 | -------------------------------------------------------------------------------- /tests/testthat/test-add_resource_path.R: -------------------------------------------------------------------------------- 1 | test_that("add_resource_path", { 2 | expect_warning( 3 | add_resource_path( 4 | "", 5 | "", 6 | warn_empty = TRUE 7 | ) 8 | ) 9 | res <- add_resource_path( 10 | "xyz", 11 | directoryPath = golem_sys("utils"), 12 | warn_empty = TRUE 13 | ) 14 | expect_equal( 15 | normalizePath( 16 | res$directoryPath, 17 | winslash = "/" 18 | ), 19 | normalizePath( 20 | golem_sys("utils"), 21 | winslash = "/" 22 | ) 23 | ) 24 | }) 25 | -------------------------------------------------------------------------------- /tests/testthat/test-add_rstudio_files.R: -------------------------------------------------------------------------------- 1 | test_that("add_rstudio_files", { 2 | for (fun in list( 3 | add_positconnect_file, 4 | add_shinyappsio_file, 5 | add_shinyserver_file 6 | )) { 7 | run_quietly_in_a_dummy_golem({ 8 | fun( 9 | open = FALSE 10 | ) 11 | expect_exists( 12 | "app.R" 13 | ) 14 | expect_true( 15 | grepl( 16 | "run_app", 17 | paste( 18 | readLines( 19 | "app.R" 20 | ), 21 | collapse = " " 22 | ) 23 | ) 24 | ) 25 | }) 26 | } 27 | }) 28 | -------------------------------------------------------------------------------- /tests/testthat/test-addins.R: -------------------------------------------------------------------------------- 1 | test_that("go_to works", { 2 | dummy_golem <- create_dummy_golem() 3 | 4 | testthat::with_mocked_bindings( 5 | rstudioapi_hasFun = function(x) { 6 | return(TRUE) 7 | }, 8 | rstudioapi_navigateToFile = function(x) { 9 | file.exists( 10 | x 11 | ) 12 | }, 13 | code = { 14 | these_all_should_be_true <- c( 15 | go_to_start( 16 | golem_wd = dummy_golem 17 | ), 18 | go_to_dev( 19 | golem_wd = dummy_golem 20 | ), 21 | go_to_deploy( 22 | golem_wd = dummy_golem 23 | ), 24 | go_to_run_dev( 25 | golem_wd = dummy_golem 26 | ), 27 | go_to_app_ui( 28 | golem_wd = dummy_golem 29 | ), 30 | go_to_app_server( 31 | golem_wd = dummy_golem 32 | ), 33 | go_to_run_app( 34 | golem_wd = dummy_golem 35 | ) 36 | ) 37 | } 38 | ) 39 | expect_true( 40 | unique( 41 | these_all_should_be_true 42 | ) 43 | ) 44 | unlink( 45 | dummy_golem, 46 | TRUE, 47 | TRUE 48 | ) 49 | }) 50 | -------------------------------------------------------------------------------- /tests/testthat/test-after_creation_msg.R: -------------------------------------------------------------------------------- 1 | test_that("after_creation_msg works", { 2 | expect_snapshot({ 3 | after_creation_message_generic( 4 | "mypkg", 5 | "inst/app/www", 6 | "myjs" 7 | ) 8 | after_creation_message_js( 9 | "mypkg", 10 | "inst/app/www", 11 | "myjs" 12 | ) 13 | after_creation_message_css( 14 | "mypkg", 15 | "inst/app/www", 16 | "mycss" 17 | ) 18 | after_creation_message_sass( 19 | "mypkg", 20 | "inst/app/www", 21 | "mysass" 22 | ) 23 | after_creation_message_html_template( 24 | "mypkg", 25 | "inst/app/www", 26 | "myhtml" 27 | ) 28 | testthat::with_mocked_bindings( 29 | fs_path_abs = paste, 30 | { 31 | after_creation_message_any_file( 32 | "mypkg", 33 | "inst/app/www", 34 | "myhtml" 35 | ) 36 | } 37 | ) 38 | file_created_dance( 39 | "inst/app/www", 40 | after_creation_message_sass, 41 | "mypkg", 42 | "inst/app/www", 43 | "mysass", 44 | open_file = FALSE 45 | ) 46 | file_already_there_dance( 47 | "inst/app/www", 48 | open_file = FALSE 49 | ) 50 | }) 51 | }) 52 | -------------------------------------------------------------------------------- /tests/testthat/test-browser_button.R: -------------------------------------------------------------------------------- 1 | test_that("browser_button works", { 2 | expect_snapshot( 3 | browser_button() 4 | ) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-bundle_resources.R: -------------------------------------------------------------------------------- 1 | test_that("multiplication works", { 2 | run_quietly_in_a_dummy_golem({ 3 | add_css_file( 4 | golem_wd = ".", 5 | "bundle", 6 | open = FALSE 7 | ) 8 | add_js_file( 9 | golem_wd = ".", 10 | "bundle", 11 | open = FALSE 12 | ) 13 | res <- bundle_resources( 14 | path = "inst/app/www", 15 | app_title = "fakename", 16 | with_sparkles = TRUE 17 | ) 18 | expect_equal( 19 | length(res), 20 | 3 21 | ) 22 | expect_true( 23 | inherits(res[[1]], "html_dependency") 24 | ) 25 | expect_true( 26 | inherits(res[[2]], "shiny.tag") 27 | ) 28 | expect_true( 29 | inherits(res[[3]], "html_dependency") 30 | ) 31 | }) 32 | }) 33 | -------------------------------------------------------------------------------- /tests/testthat/test-cats.R: -------------------------------------------------------------------------------- 1 | test_that("cats works", { 2 | expect_snapshot({ 3 | cat_green_tick("File downloaded at /tmp") 4 | cat_red_bullet("File not added (needs a valid directory)") 5 | cat_info("File copied to /tmp") 6 | cat_exists("/tmp") 7 | cat_dir_necessary() 8 | cat_start_download() 9 | cat_downloaded("/tmp") 10 | cat_start_copy() 11 | cat_copied("/tmp") 12 | cat_created("/tmp") 13 | cat_automatically_linked() 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-config.R: -------------------------------------------------------------------------------- 1 | test_that("guess_where_config works", { 2 | # Default behavior, default structure 3 | run_quietly_in_a_dummy_golem({ 4 | config <- guess_where_config( 5 | path = "." 6 | ) 7 | expect_exists( 8 | config 9 | ) 10 | }) 11 | # Default behavior, default structure 12 | run_quietly_in_a_dummy_golem({ 13 | unlink("./inst/golem-config.yml") 14 | expect_error({ 15 | guess_where_config( 16 | path = "." 17 | ) 18 | }) 19 | }) 20 | 21 | # Using the envvar, case one with a file that exists 22 | run_quietly_in_a_dummy_golem({ 23 | fs_file_copy( 24 | "./inst/golem-config.yml", 25 | "./inst/golem-config2.yml" 26 | ) 27 | withr::with_envvar( 28 | c("GOLEM_CONFIG_PATH" = "./inst/golem-config2.yml"), 29 | { 30 | config <- guess_where_config( 31 | path = "." 32 | ) 33 | expect_exists( 34 | config 35 | ) 36 | } 37 | ) 38 | }) 39 | 40 | # Using the envvar, case one with a file that exists 41 | run_quietly_in_a_dummy_golem({ 42 | withr::with_envvar( 43 | c("GOLEM_CONFIG_PATH" = "./inst/golem-config2.yml"), 44 | { 45 | expect_error( 46 | guess_where_config( 47 | path = "." 48 | ) 49 | ) 50 | } 51 | ) 52 | }) 53 | }) 54 | 55 | test_that("get_current_config works", { 56 | run_quietly_in_a_dummy_golem({ 57 | # We don't need to retest guess_where_config 58 | testthat::with_mocked_bindings( 59 | fs_file_exists = function(...) { 60 | return(FALSE) 61 | }, 62 | { 63 | unlink("./inst/golem-config.yml") 64 | expect_error(get_current_config()) 65 | } 66 | ) 67 | }) 68 | }) 69 | 70 | test_that("ask_golem_creation_upon_config works", { 71 | testthat::with_mocked_bindings( 72 | yesno = paste, 73 | { 74 | expect_snapshot( 75 | ask_golem_creation_upon_config( 76 | "/home/golem" 77 | ) 78 | ) 79 | } 80 | ) 81 | }) 82 | 83 | test_that("change_app_config_name works", { 84 | run_quietly_in_a_dummy_golem({ 85 | expect_warning({ 86 | change_app_config_name( 87 | "new_name", 88 | ".", 89 | "here" 90 | ) 91 | }) 92 | expect_true( 93 | grepl( 94 | "new_name", 95 | paste( 96 | readLines("R/app_config.R"), 97 | collapse = " " 98 | ) 99 | ) 100 | ) 101 | }) 102 | }) 103 | -------------------------------------------------------------------------------- /tests/testthat/test-disable_autoload.R: -------------------------------------------------------------------------------- 1 | test_that("disable_autoload works", { 2 | run_quietly_in_a_dummy_golem({ 3 | disable_autoload() 4 | expect_exists( 5 | file.path( 6 | "R", 7 | "_disable_autoload.R" 8 | ) 9 | ) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /tests/testthat/test-enable_roxygenize.R: -------------------------------------------------------------------------------- 1 | create_temp_rproj <- function() { 2 | temp_file <- tempfile(pattern = "test", fileext = ".Rproj") 3 | yaml::write_yaml(list(PackageRoxygenize = NULL), temp_file) 4 | return(temp_file) 5 | } 6 | 7 | 8 | test_that( 9 | "enable_roxygenize function updates the .Rproj file correctly", 10 | { 11 | # Create a temporary .Rproj file 12 | temp_rproj <- create_temp_rproj() 13 | 14 | withr::with_options( 15 | c("usethis.quiet" = TRUE), 16 | { 17 | enable_roxygenize(path = temp_rproj) 18 | } 19 | ) 20 | 21 | updated_content <- yaml::read_yaml(temp_rproj) 22 | 23 | expect_equal( 24 | updated_content[["PackageRoxygenize"]], 25 | "rd,collate,namespace" 26 | ) 27 | 28 | unlink(temp_rproj) 29 | } 30 | ) 31 | 32 | test_that("enable_roxygenize function prints correct messages", { 33 | temp_rproj <- create_temp_rproj() 34 | 35 | output <- capture.output(enable_roxygenize(path = temp_rproj)) 36 | 37 | expect_true(any(grepl("Reading", output))) 38 | expect_true(any(grepl("Enable roxygen2", output))) 39 | expect_true(any(grepl("Done", output))) 40 | 41 | unlink(temp_rproj) 42 | }) 43 | -------------------------------------------------------------------------------- /tests/testthat/test-file_endings.R: -------------------------------------------------------------------------------- 1 | # Check that every file has a proper EOF 2 | # Given that reading a file with improper EOF 3 | # Throws a warning, we'll expect_silent() the readLines() 4 | 5 | test_that( 6 | "All files have a proper EOF", 7 | { 8 | new_golem <- perform_inside_a_new_golem(function() { 9 | return(getwd()) 10 | }) 11 | withr::with_dir( 12 | new_golem, 13 | { 14 | r_files <- list.files( 15 | pattern = ".*R$", 16 | recursive = TRUE, 17 | full.names = TRUE 18 | ) 19 | 20 | for (i in r_files) { 21 | expect_silent( 22 | readLines(i) 23 | ) 24 | } 25 | js_files <- list.files(pattern = ".*js$", recursive = TRUE) 26 | 27 | for (i in js_files) { 28 | expect_silent( 29 | readLines(i) 30 | ) 31 | } 32 | 33 | css_files <- list.files(pattern = ".*css$", recursive = TRUE) 34 | 35 | for (i in css_files) { 36 | expect_silent( 37 | readLines(i) 38 | ) 39 | } 40 | } 41 | ) 42 | unlink( 43 | new_golem, 44 | TRUE, 45 | TRUE 46 | ) 47 | } 48 | ) 49 | -------------------------------------------------------------------------------- /tests/testthat/test-get_sysreqs.R: -------------------------------------------------------------------------------- 1 | test_that("get_sysreqs works", { 2 | expect_warning( 3 | get_sysreqs() 4 | ) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-globals.R: -------------------------------------------------------------------------------- 1 | test_that("set_golem_global function sets global variables correctly", { 2 | set_golem_global("test_var", "test_value") 3 | expect_equal(.golem_globals$test_var, "test_value") 4 | rm("test_var", envir = .golem_globals) 5 | 6 | set_golem_global("another_var", 123) 7 | expect_equal(.golem_globals$another_var, 123) 8 | rm("another_var", envir = .golem_globals) 9 | }) 10 | -------------------------------------------------------------------------------- /tests/testthat/test-golem-yaml-get.R: -------------------------------------------------------------------------------- 1 | test_that("get_golem_things works", { 2 | run_quietly_in_a_dummy_golem({ 3 | expect_equal( 4 | get_golem_things( 5 | "golem_version", 6 | golem_wd = "." 7 | ), 8 | "0.0.0.9000" 9 | ) 10 | 11 | expect_warning( 12 | get_golem_things( 13 | "golem_version", 14 | golem_wd = ".", 15 | path = "." 16 | ) 17 | ) 18 | 19 | expect_equal( 20 | get_golem_wd( 21 | golem_wd = "." 22 | ), 23 | getwd() 24 | ) 25 | expect_warning( 26 | get_golem_wd( 27 | pkg = "." 28 | ) 29 | ) 30 | expect_equal( 31 | get_golem_name( 32 | golem_wd = "." 33 | ), 34 | "shinyexample" 35 | ) 36 | expect_warning( 37 | get_golem_name( 38 | pkg = "." 39 | ) 40 | ) 41 | expect_equal( 42 | get_golem_version( 43 | golem_wd = "." 44 | ), 45 | "0.0.0.9000" 46 | ) 47 | expect_warning( 48 | get_golem_version( 49 | pkg = "." 50 | ) 51 | ) 52 | # Testing the fallback fun 53 | golem_config <- yaml::read_yaml( 54 | "inst/golem-config.yml", 55 | eval.expr = TRUE 56 | ) 57 | golem_config$default$golem_version <- NULL 58 | yaml::write_yaml( 59 | golem_config, 60 | "inst/golem-config.yml" 61 | ) 62 | expect_equal( 63 | get_golem_version( 64 | golem_wd = "." 65 | ), 66 | "0.0.0.9000" 67 | ) 68 | }) 69 | }) 70 | -------------------------------------------------------------------------------- /tests/testthat/test-golem-yaml-utils.R: -------------------------------------------------------------------------------- 1 | test_that("add_expr_tag adds !expr tag correctly", { 2 | tag <- list("some_expression") 3 | result <- add_expr_tag(tag) 4 | expect_equal( 5 | attr( 6 | result[[1]], 7 | "tag" 8 | ), 9 | "!expr" 10 | ) 11 | }) 12 | 13 | # Helper function to create temporary YAML files 14 | create_temp_yaml <- function() { 15 | file.copy( 16 | golem_sys( 17 | "shinyexample/inst/golem-config.yml" 18 | ), 19 | tmp <- tempfile(fileext = ".yml") 20 | ) 21 | return(tmp) 22 | } 23 | test_that( 24 | "find_and_tag_exprs tags expressions correctly", 25 | { 26 | conf_path <- create_temp_yaml() 27 | 28 | # Run the function 29 | result <- find_and_tag_exprs(conf_path) 30 | 31 | # Check that expressions are tagged correctly 32 | expect_equal( 33 | attr( 34 | result$dev$golem_wd, 35 | "tag" 36 | ), 37 | "!expr" 38 | ) 39 | 40 | # Check that non-expressions remain unchanged 41 | expect_equal( 42 | result$production$app_prod, 43 | TRUE 44 | ) 45 | 46 | # Clean up 47 | unlink(conf_path) 48 | } 49 | ) 50 | 51 | test_that( 52 | "amend_golem_config works", 53 | { 54 | run_quietly_in_a_dummy_golem({ 55 | amend_golem_config( 56 | "this", 57 | "that", 58 | config = "default", 59 | golem_wd = ".", 60 | talkative = FALSE 61 | ) 62 | expect_equal( 63 | read_yaml( 64 | eval.expr = FALSE, 65 | file.path( 66 | "inst", 67 | "golem-config.yml" 68 | ) 69 | )$default$this, 70 | "that" 71 | ) 72 | amend_golem_config( 73 | "this", 74 | "that", 75 | config = "pif", 76 | golem_wd = ".", 77 | talkative = FALSE 78 | ) 79 | 80 | expect_equal( 81 | read_yaml( 82 | eval.expr = FALSE, 83 | file.path( 84 | "inst", 85 | "golem-config.yml" 86 | ) 87 | )$pif$this, 88 | "that" 89 | ) 90 | }) 91 | } 92 | ) 93 | -------------------------------------------------------------------------------- /tests/testthat/test-golem_welcome_page.R: -------------------------------------------------------------------------------- 1 | test_that("golem_welcome_page works", { 2 | html <- golem_welcome_page() 3 | 4 | expect_true(inherits(html, "shiny.tag.list")) 5 | 6 | chr_html <- as.character(html) 7 | 8 | links_to_detect <- c( 9 | "https://golemverse.org/", 10 | "https://raw.githubusercontent.com/ThinkR-open/golem/master/inst/rstudio/templates/project/golem.png", 11 | "https://engineering-shiny.org/" 12 | ) 13 | 14 | sapply( 15 | links_to_detect, 16 | function(x) { 17 | expect_true( 18 | grepl(x, chr_html) 19 | ) 20 | } 21 | ) 22 | }) 23 | -------------------------------------------------------------------------------- /tests/testthat/test-install_dev_deps.R: -------------------------------------------------------------------------------- 1 | expect_installed <- function(pkg) { 2 | expect( 3 | rlang::is_installed(pkg), 4 | failure_message = paste0( 5 | "Package '", pkg, "' is not installed. Installed from ", 6 | getOption("repos") 7 | ) 8 | ) 9 | } 10 | 11 | test_that("install_dev_deps works", { 12 | withr::with_temp_libpaths({ 13 | install_dev_deps( 14 | force_install = TRUE 15 | ) 16 | for ( 17 | pak in dev_deps 18 | ) { 19 | expect_installed(pak) 20 | } 21 | }) 22 | }) 23 | 24 | test_that("check_dev_deps_are_installed works", { 25 | withr::with_temp_libpaths({ 26 | testthat::with_mocked_bindings( 27 | rlang_is_installed = function(...) { 28 | return(FALSE) 29 | }, 30 | { 31 | expect_message( 32 | check_dev_deps_are_installed() 33 | ) 34 | } 35 | ) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /tests/testthat/test-is_golem.R: -------------------------------------------------------------------------------- 1 | test_that("is_golem works", { 2 | to_create <- grep( 3 | "^(?!REMOVEME).*", 4 | list.files( 5 | system.file("shinyexample", package = "golem"), 6 | recursive = TRUE 7 | ), 8 | perl = TRUE, 9 | value = TRUE 10 | ) 11 | run_quietly_in_a_dummy_golem({ 12 | for (file in to_create) { 13 | file.create( 14 | file 15 | ) 16 | } 17 | expect_true( 18 | is_golem(".") 19 | ) 20 | }) 21 | expect_false( 22 | is_golem(tempdir()) 23 | ) 24 | }) 25 | -------------------------------------------------------------------------------- /tests/testthat/test-is_running.R: -------------------------------------------------------------------------------- 1 | test_that("is_running", { 2 | expect_false(is_running()) 3 | .golem_globals$running <- TRUE 4 | expect_true( 5 | is_running() 6 | ) 7 | .golem_globals$running <- FALSE 8 | }) 9 | -------------------------------------------------------------------------------- /tests/testthat/test-js.R: -------------------------------------------------------------------------------- 1 | test_that("active_js", { 2 | expect_s3_class(activate_js(), "shiny.tag") 3 | }) 4 | 5 | test_that("invoke_js", { 6 | expect_error(invoke_js()) 7 | expect_equal( 8 | invoke_js( 9 | "clickon", 10 | session = shiny::MockShinySession$new() 11 | ), 12 | list() 13 | ) 14 | }) 15 | -------------------------------------------------------------------------------- /tests/testthat/test-maintenance_page.R: -------------------------------------------------------------------------------- 1 | test_that( 2 | "maintenance page works directly and via with_golem_options()", 3 | { 4 | # 1. Test the maintenance feature directly 5 | html <- maintenance_page() 6 | expect_true( 7 | inherits( 8 | html, 9 | c("html_document", "shiny.tag.list", "list") 10 | ) 11 | ) 12 | withr::with_envvar( 13 | c("GOLEM_MAINTENANCE_ACTIVE" = TRUE), 14 | { 15 | app_options_maintenance <- with_golem_options( 16 | app = shiny::shinyApp( 17 | ui = list(), 18 | server = function(input, output, session) { 19 | shiny::htmlOutput("test") 20 | } 21 | ), 22 | golem_opts = list() 23 | ) 24 | } 25 | ) 26 | withr::with_envvar( 27 | c("GOLEM_MAINTENANCE_ACTIVE" = FALSE), 28 | { 29 | app_options_no_maintenance <- with_golem_options( 30 | app = shiny::shinyApp( 31 | ui = list(), 32 | server = function(input, output, session) { 33 | shiny::htmlOutput("test") 34 | } 35 | ), 36 | golem_opts = list() 37 | ) 38 | } 39 | ) 40 | 41 | expect_false( 42 | isTRUE( 43 | all.equal( 44 | app_options_maintenance, 45 | app_options_no_maintenance 46 | ) 47 | ) 48 | ) 49 | } 50 | ) 51 | -------------------------------------------------------------------------------- /tests/testthat/test-make_dev.R: -------------------------------------------------------------------------------- 1 | test_that("test app_dev", { 2 | withr::with_options( 3 | c( 4 | golem.app.prod = TRUE 5 | ), 6 | { 7 | expect_false(app_dev()) 8 | expect_true(app_prod()) 9 | } 10 | ) 11 | withr::with_options( 12 | c( 13 | golem.app.prod = FALSE 14 | ), 15 | { 16 | expect_true(app_dev()) 17 | expect_false(app_prod()) 18 | } 19 | ) 20 | }) 21 | 22 | test_that("test print_dev", { 23 | withr::with_options( 24 | c( 25 | golem.app.prod = FALSE 26 | ), 27 | { 28 | res <- capture.output({ 29 | print_dev("test") 30 | }) 31 | expect_true( 32 | grepl( 33 | "test", 34 | res 35 | ) 36 | ) 37 | } 38 | ) 39 | }) 40 | 41 | test_that("test make_dev", { 42 | withr::with_options( 43 | c( 44 | golem.app.prod = FALSE 45 | ), 46 | { 47 | sum_dev <- make_dev(sum) 48 | class(sum_dev) 49 | expect_equal(sum_dev(1, 2), 3) 50 | expect_type(sum_dev(1, 2), "double") 51 | expect_type(sum_dev, "closure") 52 | } 53 | ) 54 | }) 55 | 56 | test_that("test browser_button", { 57 | withr::with_options( 58 | c("golem.quiet" = FALSE), 59 | { 60 | output <- capture_output_lines(browser_button()) 61 | } 62 | ) 63 | expect_true( 64 | grepl('actionButton\\("browser", "browser"\\)', output[2]) 65 | ) 66 | expect_true( 67 | grepl('tags\\$script\\(\"\\$\\(\'#browser\'\\).hide\\(\\);\"\\)', output[3]) 68 | ) 69 | expect_true( 70 | grepl("observeEvent\\(input\\$browser", output[6]) 71 | ) 72 | expect_true( 73 | grepl(" browser()", output[7]) 74 | ) 75 | expect_true( 76 | grepl("run \\$\\('#browser'\\)\\.show\\(\\);", output[12]) 77 | ) 78 | }) 79 | -------------------------------------------------------------------------------- /tests/testthat/test-modules_fn.R: -------------------------------------------------------------------------------- 1 | test_that( 2 | "add_module works", 3 | { 4 | run_quietly_in_a_dummy_golem({ 5 | add_module( 6 | "mod1", 7 | open = FALSE, 8 | golem_wd = ".", 9 | with_test = TRUE 10 | ) 11 | expect_exists( 12 | file.path( 13 | "R", 14 | "mod_mod1.R" 15 | ) 16 | ) 17 | expect_exists( 18 | file.path( 19 | "tests", 20 | "testthat", 21 | "test-mod_mod1.R" 22 | ) 23 | ) 24 | }) 25 | } 26 | ) 27 | 28 | test_that("use_module_test", { 29 | run_quietly_in_a_dummy_golem({ 30 | add_module( 31 | "mod1", 32 | open = FALSE, 33 | golem_wd = ".", 34 | with_test = FALSE 35 | ) 36 | use_module_test( 37 | "mod1", 38 | golem_wd = ".", 39 | open = FALSE 40 | ) 41 | expect_exists( 42 | file.path( 43 | "tests", 44 | "testthat", 45 | "test-mod_mod1.R" 46 | ) 47 | ) 48 | expect_error( 49 | use_module_test( 50 | "phatom", 51 | golem_wd = ".", 52 | open = FALSE 53 | ), 54 | regex = "The module 'phatom' does not exist" 55 | ) 56 | }) 57 | }) 58 | 59 | test_that( 60 | "module_template works", 61 | { 62 | module_template( 63 | "mod1", 64 | path <- tempfile(), 65 | export = TRUE, 66 | open = FALSE 67 | ) 68 | on.exit({ 69 | unlink( 70 | path, 71 | recursive = TRUE, 72 | force = TRUE 73 | ) 74 | }) 75 | mod_read <- paste( 76 | readLines( 77 | path 78 | ), 79 | collapse = " " 80 | ) 81 | expect_true( 82 | grepl( 83 | "mod_mod1", 84 | mod_read 85 | ) 86 | ) 87 | expect_true( 88 | grepl( 89 | "@export", 90 | mod_read 91 | ) 92 | ) 93 | } 94 | ) 95 | 96 | 97 | test_that("mod_remove work", { 98 | expect_equal( 99 | mod_remove("mod_a"), 100 | "a" 101 | ) 102 | expect_equal( 103 | mod_remove("mod__moda"), 104 | "_moda" 105 | ) 106 | expect_equal( 107 | mod_remove("a_mod_a"), 108 | "a_mod_a" 109 | ) 110 | expect_equal( 111 | mod_remove("mod_mod1"), 112 | "mod1" 113 | ) 114 | }) 115 | -------------------------------------------------------------------------------- /tests/testthat/test-pkg_tools.R: -------------------------------------------------------------------------------- 1 | test_that( 2 | "daf_desc & pkg works", 3 | { 4 | run_quietly_in_a_dummy_golem({ 5 | expect_equal( 6 | daf_desc( 7 | ".", 8 | "Package" 9 | ), 10 | "shinyexample" 11 | ) 12 | expect_equal( 13 | pkg_name( 14 | "." 15 | ), 16 | "shinyexample" 17 | ) 18 | expect_equal( 19 | pkg_version( 20 | "." 21 | ), 22 | "0.0.0.9000" 23 | ) 24 | expect_equal( 25 | pkg_path(), 26 | getwd() 27 | ) 28 | }) 29 | } 30 | ) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-reload.R: -------------------------------------------------------------------------------- 1 | test_that("detach_all_attached works", { 2 | testthat::with_mocked_bindings( 3 | .package = "base", 4 | detach = function(...) { 5 | return(TRUE) 6 | }, 7 | { 8 | res <- detach_all_attached() 9 | } 10 | ) 11 | expect_true(res) 12 | }) 13 | 14 | test_that( 15 | "check_name_consistency works", 16 | { 17 | run_quietly_in_a_dummy_golem({ 18 | res <- check_name_consistency(".") 19 | expect_true(res) 20 | silent_desc <- desc::desc_set( 21 | "Package", 22 | "pif", 23 | file = "DESCRIPTION" 24 | ) 25 | expect_error(check_name_consistency(".")) 26 | }) 27 | run_quietly_in_a_dummy_golem({ 28 | res <- check_name_consistency(".") 29 | expect_true(res) 30 | write( 31 | "app_sys_2 <- function(...){system.file(..., package = 'blabla')}", 32 | "R/app_config.R", 33 | append = TRUE 34 | ) 35 | expect_error(check_name_consistency(".")) 36 | }) 37 | } 38 | ) 39 | 40 | test_that("test document_and_reload", { 41 | res <- perform_inside_a_new_golem(function() { 42 | file.create("R/sum.R") 43 | cat( 44 | "#' @export 45 | sum_golem <- function(a,b){a + b}", 46 | file = "R/sum.R" 47 | ) 48 | golem::document_and_reload() 49 | sum_golem(1, 2) 50 | }) 51 | testthat::expect_equal( 52 | res, 53 | 3 54 | ) 55 | testthat::with_mocked_bindings( 56 | roxygen2_roxygenise = function(...) { 57 | return(TRUE) 58 | }, 59 | pkgload_load_all = function(...) { 60 | return(TRUE) 61 | }, 62 | { 63 | run_quietly_in_a_dummy_golem({ 64 | expect_null( 65 | document_and_reload( 66 | "." 67 | ) 68 | ) 69 | }) 70 | } 71 | ) 72 | }) 73 | -------------------------------------------------------------------------------- /tests/testthat/test-run_dev.R: -------------------------------------------------------------------------------- 1 | test_that("run_dev works", { 2 | expect_error( 3 | run_dev( 4 | file = tempfile(), 5 | golem_wd = tempdir(), 6 | save_all = FALSE 7 | ) 8 | ) 9 | fake_run_dev <- file.path( 10 | tempdir(), 11 | "fake_run_dev.R" 12 | ) 13 | write("1 + 1", fake_run_dev) 14 | expect_equal( 15 | run_dev( 16 | file = basename(fake_run_dev), 17 | golem_wd = dirname(fake_run_dev), 18 | save_all = FALSE 19 | ), 20 | 2 21 | ) 22 | expect_equal( 23 | run_dev( 24 | file = basename(fake_run_dev), 25 | golem_wd = dirname(fake_run_dev), 26 | save_all = TRUE 27 | ), 28 | 2 29 | ) 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-sanity_check.R: -------------------------------------------------------------------------------- 1 | test_that("sanity_check works", { 2 | run_quietly_in_a_dummy_golem({ 3 | write( 4 | "browser()", 5 | file.path( 6 | ".", 7 | "R/app.R" 8 | ), 9 | append = TRUE 10 | ) 11 | write( 12 | "#TODO", 13 | file.path( 14 | ".", 15 | "R/app.R" 16 | ), 17 | append = TRUE 18 | ) 19 | write( 20 | "#TOFIX", 21 | file.path( 22 | ".", 23 | "R/app.R" 24 | ), 25 | append = TRUE 26 | ) 27 | write( 28 | "#BUG", 29 | file.path( 30 | ".", 31 | "R/app.R" 32 | ), 33 | append = TRUE 34 | ) 35 | write( 36 | "# TODO", 37 | file.path( 38 | ".", 39 | "R/app.R" 40 | ), 41 | append = TRUE 42 | ) 43 | write( 44 | "# TOFIX", 45 | file.path( 46 | ".", 47 | "R/app.R" 48 | ), 49 | append = TRUE 50 | ) 51 | write( 52 | "# BUG", 53 | file.path( 54 | ".", 55 | "R/app.R" 56 | ), 57 | append = TRUE 58 | ) 59 | res <- sanity_check( 60 | "." 61 | ) 62 | expect_true( 63 | nrow(res) == 7 64 | ) 65 | }) 66 | }) 67 | -------------------------------------------------------------------------------- /tests/testthat/test-set_golem_options.R: -------------------------------------------------------------------------------- 1 | test_that("set_golem_options works", { 2 | run_quietly_in_a_dummy_golem({ 3 | testthat::with_mocked_bindings( 4 | usethis_proj_set = function(...) { 5 | return() 6 | }, 7 | { 8 | res <- set_golem_options( 9 | golem_name = "dummygolem", 10 | golem_version = "0.0.0.912", 11 | golem_wd = ".", 12 | app_prod = FALSE, 13 | talkative = FALSE, 14 | config_file = get_current_config(".") 15 | ) 16 | expect_equal( 17 | get_golem_name( 18 | golem_wd = "." 19 | ), 20 | "dummygolem" 21 | ) 22 | expect_equal( 23 | get_golem_version( 24 | golem_wd = "." 25 | ), 26 | "0.0.0.912" 27 | ) 28 | } 29 | ) 30 | }) 31 | }) 32 | -------------------------------------------------------------------------------- /tests/testthat/test-templates.R: -------------------------------------------------------------------------------- 1 | test_that("project_hook works", { 2 | expect_true( 3 | project_hook() 4 | ) 5 | }) 6 | 7 | test_that("js_handler_template works", { 8 | tpjs <- tempfile(fileext = ".js") 9 | js_handler_template( 10 | tpjs, 11 | code = "Zach Miller" 12 | ) 13 | expect_true( 14 | grepl( 15 | "Shiny.addCustomMessageHandler", 16 | paste( 17 | readLines(tpjs), 18 | collapse = "" 19 | ) 20 | ) 21 | ) 22 | expect_true( 23 | grepl( 24 | "Zach Miller", 25 | paste( 26 | readLines(tpjs), 27 | collapse = "" 28 | ) 29 | ) 30 | ) 31 | unlink(tpjs) 32 | }) 33 | 34 | test_that("js_template works", { 35 | tpjs <- tempfile(fileext = ".js") 36 | js_template( 37 | tpjs, 38 | code = "Zach Miller" 39 | ) 40 | 41 | expect_true( 42 | grepl( 43 | "Zach Miller", 44 | paste( 45 | readLines(tpjs), 46 | collapse = "" 47 | ) 48 | ) 49 | ) 50 | unlink(tpjs) 51 | }) 52 | 53 | test_that("js_template works", { 54 | tpjs <- tempfile(fileext = ".css") 55 | css_template( 56 | tpjs, 57 | code = "Zach Miller" 58 | ) 59 | 60 | expect_true( 61 | grepl( 62 | "Zach Miller", 63 | paste( 64 | readLines(tpjs), 65 | collapse = "" 66 | ) 67 | ) 68 | ) 69 | unlink(tpjs) 70 | }) 71 | 72 | test_that("sass_template works", { 73 | tpjs <- tempfile(fileext = ".sass") 74 | sass_template( 75 | tpjs, 76 | code = "Zach Miller" 77 | ) 78 | 79 | expect_true( 80 | grepl( 81 | "Zach Miller", 82 | paste( 83 | readLines(tpjs), 84 | collapse = "" 85 | ) 86 | ) 87 | ) 88 | unlink(tpjs) 89 | }) 90 | 91 | 92 | test_that("empty_template works", { 93 | tpjs <- tempfile(fileext = ".xyz") 94 | empty_template( 95 | tpjs, 96 | code = "Zach Miller" 97 | ) 98 | 99 | expect_true( 100 | grepl( 101 | "Zach Miller", 102 | paste( 103 | readLines(tpjs), 104 | collapse = "" 105 | ) 106 | ) 107 | ) 108 | unlink(tpjs) 109 | }) 110 | -------------------------------------------------------------------------------- /tests/testthat/test-test_helpers.R: -------------------------------------------------------------------------------- 1 | test_that("test expect_shinytag", { 2 | expect_equal( 3 | capture_output( 4 | expect_shinytag(favicon("jean")) 5 | ), 6 | "" 7 | ) 8 | expect_error( 9 | expect_shinytag("pierre") 10 | ) 11 | }) 12 | 13 | test_that("test expect_shinytaglist", { 14 | expect_equal( 15 | capture_output( 16 | expect_shinytaglist( 17 | shiny::tagList() 18 | ) 19 | ), 20 | "" 21 | ) 22 | expect_error( 23 | expect_shinytaglist("test") 24 | ) 25 | }) 26 | 27 | test_that("test expect_shinytag", { 28 | testthat::with_mocked_bindings( 29 | testthat_expect_snapshot = function(...) { 30 | return(TRUE) 31 | }, 32 | { 33 | expect_message( 34 | expect_html_equal( 35 | shiny::tagList(), 36 | html = "test" 37 | ) 38 | ) 39 | expect_true( 40 | expect_html_equal( 41 | shiny::tagList() 42 | ) 43 | ) 44 | } 45 | ) 46 | }) 47 | -------------------------------------------------------------------------------- /tests/testthat/test-use_favicon.R: -------------------------------------------------------------------------------- 1 | test_that("use_favicon works", { 2 | run_quietly_in_a_dummy_golem({ 3 | testthat::with_mocked_bindings( 4 | curl_get_headers = function(...) { 5 | res <- list() 6 | attr(res, "status") <- 200 7 | res 8 | }, 9 | utils_download_file = function(path, destfile, method) { 10 | file.copy( 11 | golem_sys( 12 | "shinyexample/inst/app/www/favicon.ico" 13 | ), 14 | destfile 15 | ) 16 | }, 17 | { 18 | use_favicon() 19 | expect_true( 20 | file.exists("inst/app/www/favicon.ico") 21 | ) 22 | 23 | lapply( 24 | c( 25 | "test.jpeg", 26 | "test.bmp", 27 | "test.gif", 28 | "test.tiff" 29 | ), 30 | function(.x) { 31 | expect_error( 32 | use_favicon(path = .x) 33 | ) 34 | } 35 | ) 36 | remove_favicon() 37 | expect_false( 38 | file.exists("inst/app/www/favicon.ico") 39 | ) 40 | use_favicon( 41 | path = "https://fr.wikipedia.org//static/favicon/wikipedia.ico" 42 | ) 43 | expect_true( 44 | file.exists("inst/app/www/favicon.ico") 45 | ) 46 | } 47 | ) 48 | }) 49 | }) 50 | 51 | test_that("use_favicon fails on 404", { 52 | testthat::with_mocked_bindings( 53 | curl_get_headers = function(...) { 54 | res <- list() 55 | attr(res, "status") <- 404 56 | res 57 | }, 58 | { 59 | expect_error( 60 | use_favicon(golem_wd = "dummy") 61 | ) 62 | } 63 | ) 64 | }) 65 | 66 | test_that("use_favicon fails on error", { 67 | testthat::with_mocked_bindings( 68 | curl_get_headers = function(...) { 69 | stop("error") 70 | }, 71 | { 72 | expect_error( 73 | use_favicon(golem_wd = "dummy") 74 | ) 75 | } 76 | ) 77 | }) 78 | 79 | test_that("test favicon class", { 80 | expect_s3_class( 81 | favicon("jean", "jean"), 82 | "shiny.tag" 83 | ) 84 | }) 85 | -------------------------------------------------------------------------------- /tests/testthat/test-use_files.R: -------------------------------------------------------------------------------- 1 | test_that( 2 | "use_external_*_file works", 3 | { 4 | run_quietly_in_a_dummy_golem({ 5 | testthat::with_mocked_bindings( 6 | utils_download_file = function(url, there) { 7 | file.create(there) 8 | }, 9 | { 10 | funs_and_ext <- list( 11 | js = use_external_js_file, 12 | css = use_external_css_file, 13 | html = use_external_html_template, 14 | txt = use_external_file 15 | ) 16 | mapply( 17 | function(fun, ext) { 18 | unlink(paste0("this.", ext)) 19 | expect_error({ 20 | fun( 21 | url = paste0("this.", ext), 22 | golem_wd = ".", 23 | dir_create = TRUE 24 | ) 25 | }) 26 | path_to_file <- fun( 27 | url = paste0("this.", ext), 28 | golem_wd = "." 29 | ) 30 | expect_exists( 31 | path_to_file 32 | ) 33 | }, 34 | funs_and_ext, 35 | names(funs_and_ext) 36 | ) 37 | } 38 | ) 39 | }) 40 | } 41 | ) 42 | 43 | test_that( 44 | "use_internal_*_file works", 45 | { 46 | run_quietly_in_a_dummy_golem({ 47 | testthat::with_mocked_bindings( 48 | fs_file_copy = function(url, where) { 49 | file.create(where) 50 | }, 51 | { 52 | funs_and_ext <- list( 53 | js = use_internal_js_file, 54 | css = use_internal_css_file, 55 | html = use_internal_html_template, 56 | txt = use_internal_file 57 | ) 58 | mapply( 59 | function(fun, ext) { 60 | if (ext != "txt") { 61 | expect_error( 62 | fun( 63 | path = "this.nop", 64 | golem_wd = "." 65 | ) 66 | ) 67 | } 68 | path_to_file <- fun( 69 | path = paste0("this.", ext), 70 | golem_wd = "." 71 | ) 72 | expect_exists( 73 | path_to_file 74 | ) 75 | expect_equal( 76 | file_ext(path_to_file), 77 | ext 78 | ) 79 | }, 80 | funs_and_ext, 81 | names(funs_and_ext) 82 | ) 83 | } 84 | ) 85 | }) 86 | } 87 | ) 88 | -------------------------------------------------------------------------------- /tests/testthat/test-use_files_external_tools.R: -------------------------------------------------------------------------------- 1 | test_that("check_url_has_the_correct_extension(url, where) works", { 2 | testthat::expect_snapshot(error = TRUE, { 3 | check_url_has_the_correct_extension( 4 | "https://www.google.com", 5 | "js" 6 | ) 7 | }) 8 | expect_error({ 9 | check_url_has_the_correct_extension( 10 | "https://www.google.com", 11 | "js" 12 | ) 13 | }) 14 | testthat::expect_null( 15 | check_url_has_the_correct_extension( 16 | "https://www.google.com/test.js", 17 | "js" 18 | ) 19 | ) 20 | }) 21 | 22 | 23 | test_that("download_external(url, where) works", { 24 | testthat::expect_snapshot({ 25 | testthat::with_mocked_bindings( 26 | utils_download_file = function(url, where) { 27 | print(url) 28 | print(where) 29 | }, 30 | { 31 | download_external( 32 | "https://www.google.com", 33 | "inst/app/www/google.html" 34 | ) 35 | } 36 | ) 37 | }) 38 | }) 39 | -------------------------------------------------------------------------------- /tests/testthat/test-use_files_internal_tools.R: -------------------------------------------------------------------------------- 1 | test_that("copy_internal_file works", { 2 | testthat::expect_snapshot({ 3 | testthat::with_mocked_bindings( 4 | copy_internal_file = function(path, where) { 5 | print(path) 6 | print(where) 7 | }, 8 | { 9 | copy_internal_file( 10 | "~/here/this.css", 11 | "inst/app/this.css" 12 | ) 13 | } 14 | ) 15 | }) 16 | }) 17 | 18 | test_that("check_url_has_the_correct_extension(url, where) works", { 19 | testthat::expect_snapshot(error = TRUE, { 20 | check_file_has_the_correct_extension( 21 | "https://www.google.com", 22 | "js" 23 | ) 24 | }) 25 | expect_error({ 26 | check_file_has_the_correct_extension( 27 | "https://www.google.com", 28 | "js" 29 | ) 30 | }) 31 | testthat::expect_null( 32 | check_file_has_the_correct_extension( 33 | "https://www.google.com/test.js", 34 | "js" 35 | ) 36 | ) 37 | }) 38 | -------------------------------------------------------------------------------- /tests/testthat/test-use_files_shared_tools.R: -------------------------------------------------------------------------------- 1 | test_that("build_name works as expected", { 2 | expect_equal( 3 | build_name( 4 | "example.txt", 5 | "http://example.com/file.txt" 6 | ), 7 | "example" 8 | ) 9 | 10 | expect_equal( 11 | build_name(NULL, "http://example.com/file.txt"), 12 | "file" 13 | ) 14 | 15 | expect_equal( 16 | build_name(url = "http://example.com/file.txt"), 17 | "file" 18 | ) 19 | 20 | expect_equal( 21 | build_name("example", "http://example.com/file.txt"), 22 | "example" 23 | ) 24 | 25 | expect_error( 26 | build_name( 27 | c("name1", "name2"), 28 | "http://example.com/file.txt" 29 | ) 30 | ) 31 | }) 32 | 33 | test_that("check_directory_exists works as expected", { 34 | expect_error( 35 | check_directory_exists("inst/app/www") 36 | ) 37 | expect_null( 38 | check_directory_exists(getwd()) 39 | ) 40 | }) 41 | 42 | test_that("check_directory_exists works as expected", { 43 | expect_snapshot( 44 | error = TRUE, 45 | { 46 | check_directory_exists("inst/app/www") 47 | } 48 | ) 49 | expect_error( 50 | check_directory_exists("inst/app/www") 51 | ) 52 | expect_null( 53 | check_directory_exists(getwd()) 54 | ) 55 | }) 56 | 57 | test_that("check_file_exists works as expected", { 58 | file <- tempfile(fileext = ".txt") 59 | file.create(file) 60 | expect_error( 61 | check_file_exists(file) 62 | ) 63 | expect_null( 64 | check_file_exists(tempfile(fileext = ".txt")) 65 | ) 66 | unlink(file) 67 | }) 68 | -------------------------------------------------------------------------------- /tests/testthat/test-use_readme.R: -------------------------------------------------------------------------------- 1 | test_that("generate_readme_tmpl works", { 2 | res <- generate_readme_tmpl("my_pkg") 3 | expect_true( 4 | grepl("my_pkg", paste(res, collapse = " ")) 5 | ) 6 | expect_true( 7 | grepl("my_pkg::run_app()", paste(res, collapse = " ")) 8 | ) 9 | expect_true( 10 | grepl("covr::package_coverage", paste(res, collapse = " ")) 11 | ) 12 | expect_true( 13 | grepl("unloadNamespace", paste(res, collapse = " ")) 14 | ) 15 | expect_true( 16 | grepl("devtools::check", paste(res, collapse = " ")) 17 | ) 18 | }) 19 | 20 | 21 | test_that("check_overwrite works", { 22 | this_file_will_be_removed <- tempfile(fileext = ".Rmd") 23 | write("hello world", this_file_will_be_removed) 24 | 25 | expect_error( 26 | check_overwrite(FALSE, this_file_will_be_removed), 27 | "README.Rmd already exists. Set `overwrite = TRUE` to overwrite." 28 | ) 29 | # Check if file still exists 30 | expect_true(file.exists(golem_sys("utils/empty_readme.Rmd"))) 31 | 32 | # Remove file via check_overwrite setting overwrite=TRUE 33 | check_overwrite(TRUE, this_file_will_be_removed) 34 | # Check that file is indeed removed 35 | expect_false(file.exists(this_file_will_be_removed)) 36 | }) 37 | 38 | test_that("use_readme_rmd works", { 39 | withr::with_dir(tempdir(), { 40 | testthat::with_mocked_bindings( 41 | usethis_use_readme_rmd = function(open) { 42 | return(open) 43 | }, 44 | code = { 45 | expect_true( 46 | use_readme_rmd( 47 | open = FALSE, 48 | overwrite = TRUE, 49 | golem_wd = getwd(), 50 | pkg_name = "rand_name" 51 | ) 52 | ) 53 | expect_true( 54 | file.exists("README.Rmd") 55 | ) 56 | } 57 | ) 58 | }) 59 | }) 60 | -------------------------------------------------------------------------------- /tests/testthat/test-use_recommended.R: -------------------------------------------------------------------------------- 1 | test_that("use_recommended_deps works", { 2 | testthat::with_mocked_bindings( 3 | usethis_use_package = identity, 4 | { 5 | withr::with_options( 6 | c("usethis.quiet" = TRUE), 7 | { 8 | expect_warning( 9 | use_recommended_deps( 10 | tempdir() 11 | ) 12 | ) 13 | } 14 | ) 15 | } 16 | ) 17 | }) 18 | 19 | test_that( 20 | "use_recommended_tests works", 21 | { 22 | run_quietly_in_a_dummy_golem({ 23 | testthat::with_mocked_bindings( 24 | usethis_use_spell_check = function(...) { 25 | file.create( 26 | "tests/spelling.R" 27 | ) 28 | }, 29 | { 30 | use_recommended_tests( 31 | golem_wd = "." 32 | ) 33 | 34 | expect_exists( 35 | file.path( 36 | "tests", 37 | "testthat", 38 | "test-golem-recommended.R" 39 | ) 40 | ) 41 | expect_error( 42 | use_recommended_tests( 43 | golem_wd = "." 44 | ) 45 | ) 46 | } 47 | ) 48 | }) 49 | # Testing adding testthat if not there 50 | run_quietly_in_a_dummy_golem({ 51 | testthat::with_mocked_bindings( 52 | usethis_use_testthat = function() { 53 | dir.create("tests") 54 | dir.create("tests/testthat") 55 | file.create( 56 | "tests/testthat.R" 57 | ) 58 | }, 59 | { 60 | unlink("tests", TRUE, TRUE) 61 | use_recommended_tests( 62 | golem_wd = ".", 63 | spellcheck = FALSE 64 | ) 65 | 66 | expect_exists( 67 | file.path( 68 | "tests", 69 | "testthat", 70 | "test-golem-recommended.R" 71 | ) 72 | ) 73 | } 74 | ) 75 | }) 76 | # Testing adding testthat if processx 77 | # is not available 78 | run_quietly_in_a_dummy_golem({ 79 | testthat::with_mocked_bindings( 80 | usethis_use_testthat = function() { 81 | dir.create("tests") 82 | dir.create("tests/testthat") 83 | file.create( 84 | "tests/testthat.R" 85 | ) 86 | }, 87 | { 88 | use_recommended_tests( 89 | golem_wd = ".", 90 | spellcheck = FALSE 91 | ) 92 | } 93 | ) 94 | }) 95 | } 96 | ) 97 | -------------------------------------------------------------------------------- /tests/testthat/test-use_utils.R: -------------------------------------------------------------------------------- 1 | test_that("use_utils_ui works", { 2 | run_quietly_in_a_dummy_golem({ 3 | use_utils_ui(".") 4 | expect_exists( 5 | file.path( 6 | ".", 7 | "R/golem_utils_ui.R" 8 | ) 9 | ) 10 | remove_file( 11 | file.path( 12 | ".", 13 | "R/golem_utils_ui.R" 14 | ) 15 | ) 16 | 17 | use_utils_ui( 18 | ".", 19 | with_test = TRUE 20 | ) 21 | # Testint that the function is 22 | # indempotent by running it twice 23 | use_utils_ui( 24 | ".", 25 | with_test = TRUE 26 | ) 27 | 28 | expect_exists( 29 | file.path( 30 | ".", 31 | "R/golem_utils_ui.R" 32 | ) 33 | ) 34 | expect_exists( 35 | file.path( 36 | ".", 37 | "tests/testthat/test-golem_utils_ui.R" 38 | ) 39 | ) 40 | 41 | # We test that we can still add the tests even if the utils ui 42 | # is already there 43 | remove_file( 44 | file.path( 45 | ".", 46 | "R/golem_utils_ui.R" 47 | ) 48 | ) 49 | use_utils_ui( 50 | ".", 51 | with_test = TRUE 52 | ) 53 | 54 | expect_exists( 55 | file.path( 56 | ".", 57 | "R/golem_utils_ui.R" 58 | ) 59 | ) 60 | expect_exists( 61 | file.path( 62 | ".", 63 | "tests/testthat/test-golem_utils_ui.R" 64 | ) 65 | ) 66 | }) 67 | }) 68 | 69 | test_that("use_utils_server works", { 70 | run_quietly_in_a_dummy_golem({ 71 | use_utils_server(".") 72 | expect_exists( 73 | file.path( 74 | ".", 75 | "R/golem_utils_server.R" 76 | ) 77 | ) 78 | remove_file( 79 | file.path( 80 | ".", 81 | "R/golem_utils_server.R" 82 | ) 83 | ) 84 | use_utils_server( 85 | ".", 86 | with_test = TRUE 87 | ) 88 | # Testing the fun is indempotent 89 | use_utils_server( 90 | ".", 91 | with_test = TRUE 92 | ) 93 | 94 | expect_exists( 95 | file.path( 96 | ".", 97 | "R/golem_utils_server.R" 98 | ) 99 | ) 100 | expect_exists( 101 | file.path( 102 | ".", 103 | "tests/testthat/test-golem_utils_server.R" 104 | ) 105 | ) 106 | remove_file( 107 | file.path( 108 | ".", 109 | "R/golem_utils_server.R" 110 | ) 111 | ) 112 | use_utils_server( 113 | ".", 114 | with_test = TRUE 115 | ) 116 | expect_exists( 117 | file.path( 118 | ".", 119 | "R/golem_utils_server.R" 120 | ) 121 | ) 122 | expect_exists( 123 | file.path( 124 | ".", 125 | "tests/testthat/test-golem_utils_server.R" 126 | ) 127 | ) 128 | }) 129 | }) 130 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/d-js.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "04. JavaScript" 3 | author: "Colin Fay" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{04 - JavaScript} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | 17 | 18 | ```{r setup, include = FALSE} 19 | knitr::opts_chunk$set( 20 | collapse = TRUE, 21 | comment = "#>" 22 | ) 23 | ``` 24 | 25 | ## Using `{golem}` js functions 26 | 27 | `{golem}` comes with a series of JavaScript functions that you can call from the server. These functions are added by default with `bundle_resources()` . 28 | 29 | Then they are called with `golem::invoke_js("fonction", "ui_element")`. 30 | 31 | This `ui_element` define the UI element to interact with. It can be a full jQuery selector, an id or a class. Note that you can add several elements and iterate other them. 32 | 33 | `invoke_js` can be used with any function defined in a [JavaScript Custom Handler](https://shiny.rstudio.com/articles/communicating-with-js.html#from-r-to-javascript), that you can build with `golem::add_js_handler()`. 34 | 35 | ### `golem::invoke_js()` 36 | 37 | + `showid` & `hideid`, `showclass` & `hideclass` show and hide elements through their id or class. 38 | 39 | ```{r eval = FALSE} 40 | golem::invoke_js("showid", ns("plot")) 41 | ``` 42 | 43 | + `showhref` & `hidehref` hide and show a link by trying to match the `href` content. 44 | 45 | ```{r eval = FALSE} 46 | golem::invoke_js("showhref", "panel2") 47 | ``` 48 | 49 | + `clickon` click on the element. You have to use the full jQuery selector. 50 | 51 | + `show` & `hide` show and hide elements, using the full jQuery selector. 52 | 53 | + `disable` & `reable` able and disable specific element, using the full jQuery selector. 54 | 55 | See `?golem::activate_js()` for the full list. 56 | 57 | ### A quick intro to jQuery selectors 58 | 59 | + `#plop`: the element with the id `plop` 60 | 61 | + `.pouet`: elements of class `pouet` 62 | 63 | + `"button:contains('this')"`: buttons with a text containing `'this'` 64 | 65 | Note that in html, tags contains attributes. For example: 66 | 67 | ``` html 68 | ThinkR 69 | ``` 70 | 71 | contains `href` & `data-value`. You can refer to these attributes with `[]` after the tag name. 72 | 73 | + `a[href = "https://thinkr.fr"]`: link with `href` being `https://thinkr.fr` 74 | 75 | + `a[data-value="panel2"]`: link with `data-value` being `"panel2"` 76 | -------------------------------------------------------------------------------- /vignettes/golem_cheatsheet_V0.1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/golem/3a5c7a46351f7fb3f8ba9d2e6b22a92c13d282c2/vignettes/golem_cheatsheet_V0.1.jpg -------------------------------------------------------------------------------- /vignettes/golemtemplate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/golem/3a5c7a46351f7fb3f8ba9d2e6b22a92c13d282c2/vignettes/golemtemplate.png -------------------------------------------------------------------------------- /vignettes/h-resources.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Resources" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Resources} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | The `golem` package is part of the [`{golemverse}`](https://golemverse.org/), a series of tools for Shiny. 11 | A list of various `golem` related resources (tutorials, video, blog post,...) can be found [here](https://golemverse.org/resources/). 12 | 13 | # Examples apps 14 | 15 | You can find apps made by [ThinkR](https://thinkr.fr/) using `golem` here: 16 | 17 | -