-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
333 lines (241 loc) · 9.81 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# {diades.atlas}
<!-- badges: start -->
[](https://github.com/inrae/diades.atlas/actions)
<!-- badges: end -->
A Shiny application to explore data.
# Installation
```{r, eval=FALSE}
remotes::install_github('inrae/diades.atlas')
```
# Websites for validations :
- Package documentation : https://inrae.github.io/diades.atlas/
- Package documentation (development version) : https://inrae.github.io/diades.atlas/dev/
- Shiny App : https://connect.thinkr.fr/diadesatlasui18n/
# Translation
All translations are stored in csv files in "inst/". If there are corrections to be made, existing texts on the app to be translated, only these 3 files have to be modified:
+ `inst/translation_help.csv`
+ `inst/translation_iucn.csv`
+ `inst/translation.csv`
After modifications in a branch, propose a Pull Request to the _main_ branch:
- On the home page of the project, click on Pull Request
- Then on "New Pull Request".
- In the "Compare Changes" section, choose your branch in the right drop-down menu "compare:".
- Then "Create Pull Request", twice.
- You can check in the 'Files changed' tab what you have changed.
Once the PR is accepted, the changes should appear in the app the next time it is deployed. There is nothing to do.
For more information, or for instructions on how to prepare the application for new languages or areas to be translated, refer to the "dev/translation.Rmd" file.
In all cases, developers will need to
- have access to the PostGis database (see "Backend requirement" below)
- follow the content of "dev/translation.Rmd" during each update.
# Userguide
The userguide is included in English in "data-raw/userguide.Rmd". This version is to be included in the vignettes to appear on the documentation website.
Users can create other translations of this userguide.
- Copy the english Rmd file and change the name of the file
- Keep the images, but change the text for your language
- User can then knit the document as `pdf_document`.
- The translated Rmd file can stay in the "data-raw/" directory and be commit and push to GitHub
# Retrieve package and develop
You can get this package and propose modifications of the code.
1. Clone in RStudio
+ File > New Project > Version Control > Git
+ Use URL: https://github.com/inrae/diades.atlas
2. In the RStudio "Git" Pane
+ Create a "New branch" with your name
3. Define your credentials for the database
+ Create a ".Renviron" file with `usethis::edit_r_environ()`
+ Use the correct names and passwords to fill as below
+ This file will stay on your computer
```
POSTGRES_DBNAME="diades"
POSTGRES_HOST="host-url"
POSTGRES_USER="username"
POSTGRES_PORT=5432
POSTGRES_PASS="user-password"
```
+ Restart RStudio
+ Verify these variables are correctly read
```r
Sys.getenv("POSTGRES_USER")
```
4. You may need to install dependencies with the same packages than the developers
```r
renv::restore()
```
_{renv} may be tricky with multiple OS. Be kind._
5. Run `pkgload::load_all()` in the R Console
+ This loads all existing functions stored in "R/" directory
6. Open a Rmd in "data-raw/" like "data-raw/be-page4-future.Rmd"
+ You should be able to run it chunk by chunk
+ Do not forget to close connection to the database at the end
7. You can test modifications of the code in "R/"
+ After each modification, run `pkgload::load_all()` before testing in the Rmd
8. After each modification, it is necessary to run `devtools::check()`
# Exploration of database out of Shiny application
You can use this package without opening the Shiny application.
See vignette "data-raw/aa-a-exploration_data.Rmd"
# Test the application locally
To run the Shiny application on your computer, you need to meet the "Backend Requirements" (see the section below).
This means, at least, having access to the database: set your database connection information and your credentials as specified in section "PostGIS".
You may need to update your package installation using:
```{r, eval=FALSE}
renv::restore()
```
Then you can run in the R Console:
```{r, eval=FALSE}
golem::run_dev()
```
# Put in Production
Update Docker for deployment: https://gitlab.irstea.fr/diades/diades.atlas.deploy/
On https://gitlab.irstea.fr/diades/diades.atlas.deploy/, there are also details on how to test the docker-compose locally. At least try to build it locally before release.
```sh
docker build -t gitlab-registry.irstea.fr/diades/diades.atlas.deploy/app .
```
# Backend requirement
## PostGis
To update the translations or to run the shiny application locally, the PostGis database is required.
To be able to connect to a PostGis instance the user needs to define some golem config parameters and environment variables.
### golem config parameters
Those are stored in `inst/golem-config.yml` and can be modified as such:
```{r eval=FALSE}
# database name
golem::amend_golem_config(
"POSTGRES_DBNAME",
"diades" # Changer ici le nom de la base de données
)
# database host URL
golem::amend_golem_config(
"POSTGRES_HOST",
"localhost" # Changer ici l'URL de la base
)
# database port access
golem::amend_golem_config(
"POSTGRES_PORT",
"5432" # Changer ici le port
)
```
**If you change these lines to set the real values, be sure to set them back with the examples below before commit, to avoid sending your credentials on Git.**
Run the script below once, and you'll be protected of sending your credentials accidentally.
```{r, eval=FALSE}
usethis::use_git_hook(
"pre-commit",
script = c("#!/bin/bash
CONFIG=($(git diff --cached --name-only | grep -Ei '^inst/golem-config\\.yml$'))
if [[ ${#CONFIG[@]} == 1 ]]; then
echo -e \"You added inst/golem-config.yml. Is that really what you want?\nYou may not want to commit your credentials.\nIf this is really what you want, use 'git commit --no-verify' to override this check.\"
exit 1
fi
",
usethis:::render_template("readme-rmd-pre-commit.sh")
))
```
### Environment variables
The POSTGRES_USER and POSTGRES_PASS __must not be versioned__ with the app.
To avoid setting those environment variables every time you want to run the app,
they should be saved in a local .Renviron file. To define one for your own copy of
the project run this command:
```{r eval=FALSE}
usethis::edit_r_environ(scope = "project")
```
and add the following lines
```{r eval=FALSE}
# database username with Read access
POSTGRES_USER=diadesatlas_owner # Changer ici le username
# database password for the user
POSTGRES_PASS=thinkrpassword # Changer ici le password
```
Again make sure not to track this project .Renviron with git.
### Dev - ThinkR PostGis DB
If you do not have direct access to the database, a copy can be used for development.
Please refer to the doc in the {diadesdata} repo on ThinkR's forge (restricted access): Section "Pull and Use".
### Checks
Verify connexion to database works
_Whether you are connected to the development or the production database, this should work correctly_
```{r, eval=FALSE}
pkgload::load_all()
session <- new.env()
connect(session)
con <- get_con(session)
DBI::dbListTables(con)
DBI::dbDisconnect(con)
```
## Dev - Mongo
To run the Shiny application locally in the same conditions as in production, it is better to have a Mongo database. For dev, you need to run the following on your machine:
```
docker run --name=mongo --rm -p 2811:27017 -e MONGO_INITDB_ROOT_USERNAME=Colin -e MONGO_INITDB_ROOT_PASSWORD=AsAboveSoBelow789123 mongo:4.0
```
Stop it at the end of your development process
```
docker kill mongo
```
If Mongo database is not available, a local temporary cache will be use in the RAM of your machine.
# Dev - Data update requires update unit test expected outputs
If the database is updated, model outputs may change.
It may be necessary to run simulation before unit tests.
```{r, eval=FALSE}
source(here::here("data-raw/altas_simulation.R"))
```
# Dev - update and include vignettes in the package
Vignettes are compiled manually by developers.
Raw vignettes are stored in "data-raw".
Instructions to compile them are in the vignette itself.
However, they can all be prepared from this script:
```{r, eval=FALSE}
remotes::install_local(upgrade = "never", force = TRUE)
file.copy(here::here("dev", "translation.Rmd"),
here::here("data-raw", "translation.Rmd"))
all_vignettes <- c(
"aa-a-exploration_data",
"aa-data-exploration-and-preparation",
"bb-page1-catch-bycatch",
"bc-page2-present",
"bd-page3-climate-change",
"be-page4-future",
"translation",
"userguide")
for (vignette_name in all_vignettes) {
# vignette_name <- all_vignettes[6]
vignette_file <- paste0(vignette_name, ".Rmd")
rmarkdown::render(
input = here::here(file.path("data-raw", vignette_file)),
output_format = "rmarkdown::html_vignette",
output_options = list(toc = TRUE),
output_file = here::here(file.path("vignettes", vignette_file))
)
# Add header for title
lines <- readLines(here::here(file.path("vignettes", vignette_file)))
cat(
glue::glue('---
title: ".{vignette_name}."
output: rmarkdown::html_vignette
vignette: >
%\\VignetteIndexEntry{.{vignette_name}.}
%\\VignetteEngine{knitr::rmarkdown}
%\\VignetteEncoding{UTF-8}
---
', .open = ".{", .close = "}."),
lines,
sep = "\n",
file = here::here(file.path("vignettes", vignette_file))
)
}
file.remove(here::here("data-raw", "translation.Rmd"))
# Add unit tests report
# remotes::install_github("metrumresearchgroup/covrpage")
# You may need to run with interactive session.
# Do not know why...
# debugonce(covrpage::covrpage)
covrpage::covrpage(vignette = TRUE)
file.remove("tests/README.md")
```