/
shiny_apps.Rmd
212 lines (146 loc) · 6.33 KB
/
shiny_apps.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
---
title: "Shiny Apps Workshop"
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
## Welcome!
In this workshop we will be walking through the steps needed to install and use
a Shiny App on your computer.
This workshop has three main sections:
1. Installing Software
2. Introducing the software
3. Exploring the software
## Installing Software
The first step is to install the software. In our case, we will be installing
- [R](https://cran.rstudio.com/)
- [RStudio](https://posit.co/download/rstudio-desktop/)
- bcgwcat (a Shiny App)
- bcaquiferdata (a Shiny App)
### R & RStudio
We can install R and RStudio by clicking on the links above and following the
download instructions.
**Note:** For our minimal use of R, we could probably get away with not installing RStudio,
so if you would prefer, you may skip the RStudio step.
### R packages
Now we will **open** RStudio (which will use R; or we can skip RStudio and just open R)
and will install the Apps.
#### Install pak
First, we need to install an R package called 'pak'.
To do this, we're going to send some commands to the R console.
- First we'll open R/RStudio
- Next we'll locate the console
- This is an open window with the name "console" or with text referring to the R version:
```
R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: ...
```
- Now, in the console, at the prompt (`>`) type (or copy/paste) the following and hit Enter
```{r}
#| eval: false
install.packages("pak", dependencies = TRUE)
```
- Wait for this installation to complete
- When complete you'll see the prompt again (`>`) as well as `* DONE (pak)`
> **Awesome! You just installed your first R package 🎉**
#### Install Build Tools {.tabset}
##### Automatically with R
Now we'll check that our computers have what they need to install the other packages.
Because we're using custom software tools, some systems (Windows for one), often
need R-specific build tools to install them.
Run the following at the prompt (`>`), and install build tools if prompted.
```{r}
#| eval: false
pkgbuild::check_build_tools()
```
##### Troubleshooting
Best is to use the `check_build_tools()` function to automate this, but
if you have trouble installing the build tools, you can install them by hand here:
<https://cran.r-project.org/bin/windows/Rtools/rtools43/files/rtools43-5958-5975.exe>
#### Install Shiny Apps {.tabset}
##### Installing
Now that we have pak and our systems are ready, we can install the packages we want to play with.
> **Why two different ways of installing packages?**
>
> *pak is a package stored on the CRAN server, so we can download it directly with `install.packages()`,
however, many of our custom R packages used at BC Gov are stored on GitHub, and so need to be installed from there.*
> *The pak package provides functions we can use to do that.*
Again in the console, at the prompt (`>`) we'll type the following commands and hit Enter after each.
```{r}
#| eval: false
pak::pkg_install("bcgov/bcgwcat", upgrade = TRUE)
pak::pkg_install("bcgov/bcaquiferdata", upgrade = TRUE)
```
Here, we're using the pak function, `pkg_install()` to install two R packages (with Shiny Apps)
from the `bcgov` organization on GitHub.
##### Troubleshooting
Generally speaking, the vast majority of problems arise through out of date packages.
R and R packages change constantly and the best way to avoid problems is to keep things up-to-date.
This is why the installation code says `upgrade = TRUE` to ensure that packages are always updated.
This process is actually installing a bunch of packages upon which our focal
packages depend. So if we run into problems with any of these, we'll need to fix
them before we can resume installing our packages.
If you run into problems with a specific package, the best thing to do is to
try installing that package directly with pak. For example, if we have a
hard time with the 'dplyr' package, we could try...
```{r}
#| eval: false
pak:pkg_install("dplyr")
```
If that succeeds, we'll try again with the installation of our focal package...
```{r}
#| eval: false
pak:pkg_install("bcgov/bcgwcat")
```
Rinse and repeat 😉
## Introducing the Software
In this section, Steffi will guide you through the use of the two Shiny Apps
we just downloaded, and will demonstrate use of a third which is currently under
development.
### bcgwcat
- **Documentation and Website** - https://bcgov.github.io/bcgwcat/
- **Shiny App Tutorial** - https://bcgov.github.io/bcgwcat/articles/bcgwcat.html
- **To launch the Shiny App**
```{r}
#| eval: false
bcgwcat::gw_app()
```
- **EMS IDs we will be playing with today**
EMS ID | WTN | Aquifer # | OW# | Location | Aquifer Type
------- | ------ | ----- | --- | ------ | --------------
1401077 | 25272 | 1271 | 124 | Charlie Lake | Bedrock
1401059 | 26549 | 15 | 8 | Abbotsford | Unconsolidated
E218240 | 41479 | 97 | 320 | Cobble Hill | Unconsolidated
E105920 | 14947 | 158 | 217 | Grand Forks | Unconsolidated
1401808 | 44358 | 464 | 262 | Kelowna | Unconsolidated
1401448 | 42266 | 1216 | 255 | Chilliwack | Bedrock
E282789 | 85327 | 211 | 388 | Nanaimo | Bedrock
E284491 | 102925 | 664 | 389 | Qualicum Beach | Unconsolidated
E255156 | 84697 | 41 | 360 | Langley | Unconsolidated
E311344 | 115691 | 194 | 467 | Osoyoos | Unconsolidated
You can play with them one at a time, or copy and paste a series of them:
1401077, 1401059, E218240, E105920, 1401808, 1401448, E282789, E284491, E255156, E311344
### bcaquiferdata
- **Documentation and Website** - https://bcgov.github.io/bcaquiferdata/
- **Shiny App Tutorial** - https://bcgov.github.io/bcaquiferdata/articles/bcaquiferdata.html
- **To launch the Shiny App**
```{r}
#| eval: false
bcaquiferdata::aq_app()
```
- **The shape files we will be playing with will be provided as a link during the workshop**
### fasstrshiny
- **Documentation and Website** - https://bcgov.github.io/fasstrshiny/
## Exploring the Software
Now it's your turn!
Try exploring some EMS data with bcgwcat.
Try out your own watershed shape file with bcaquiferdata.
- Try to break the software!
- If anything doesn't work as you think it should, let Steffi know
- Get an error? Let Steffi know
- Have a great idea of what it should/could do? Let Steffi know
Enjoy!