-
Notifications
You must be signed in to change notification settings - Fork 1
/
introduction.qmd
189 lines (131 loc) · 5.46 KB
/
introduction.qmd
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
---
title: "Introduction to Shiny"
subtitle: "Session - Introduction"
---
## Agenda - session one (about 2 hours)
Chapter overview
::: {.fragment .fade-in}
Introduction and getting started
:::
::: {.fragment .fade-in}
What is Shiny?
:::
::: {.fragment .fade-in}
--------- Break -----------
:::
::: {.fragment .fade-in}
What does it do?
:::
::: {.fragment .fade-in}
Intro to reactivity
:::
::: {.fragment .fade-in}
Application 1 - minimal (Your first application)\
Application 2 - Sitrep (Situation Report)
:::
::: {.fragment .fade-in}
Reactive expressions
:::
::: {.fragment .fade-in}
(Optional)\
NSE in Shiny applications\
Bookmarks
:::
::: {.fragment .fade-in}
--------- Course end -----------
:::
## Agenda - session two (about 2 hours)
Chapter overview
::: {.fragment .fade-in}
--------- Course end -----------
:::
## Agenda - session three (about 2 hours)
Chapter overview
::: {.fragment .fade-in}
--------- Course end -----------
:::
## What is Shiny?
::: incremental
- Shiny is a web application programming framework
- The language of the web (HTML, JavaScript, and CSS) all called from R
- It requires no knowledge of HTML, JavaScript, or CSS, but if you have that knowledge you can add more of these languages
:::
## Let's create a shiny app - on a computer
::: incremental
- Go to `File > New Project... > New Directory`
- Select `Shiny Application`
- Browse to the location you want the new folder to go to
- Name your new project!
:::
. . .
::: {.callout-note collapse="false" appearance="default" icon="true"}
## Projects
- Using projects is a good habit to get into
- Creating a specific project through the RStudio provides all the relevant documents needed
:::
## Let's create a shiny template app - in Posit Cloud
::: incremental
- Go to `File > New File > Shiny Web App...`
- Or use the short menu below `File`
- Name your new project!
:::
. . .
::: {.callout-warning collapse="false" appearance="default" icon="true"}
## Posit Cloud workspaces are all projects!
- Because the Cloud is a project it doesn't need creating
- What we do here you can also do on your own computer
:::
## Running the app
![](img/screenshot-run-app.PNG){fig-alt="Screenshot of the RStudio pane under Tools and Help with the Run app icon and words" fig-align="center" width="582"}
Changing the inputs (from the slider) changes the outputs (the chart)
## Viewing as a pop-up... or not
::: {.info data-latex=""}
![](img/rstudio_run_app.png)
You can change whether the app opens in a separate window in RStudio, the RStudio viewer pane, or externally in your web browser. Use whichever works best for you and your computer setup.
:::
## Listening?
Before closing the app look at the R Console:
```{r}
#> Listening on http://127.0.0.1:3827
```
127.0.0.1 “this computer” and 3827 is a randomly assigned port number.
. . .
:::{.callout-important collapse=false appearance='default' icon=true}
## R is busy!
- The R prompt isn't visible
- The console toolbar has a stop sign icon
- No other commands can be used until the Shiny app is stopped!
- To stop click the stop sign, `Esc` or `Ctrl + C` in some programs
:::
## Developing a Shiny app
The workflow is:
::: {.incremental}
- Write code
- Start app
- Play with app
- Write more code
- Repeat
- And in RStudio you don't need to stop and start just `Reload app`
:::
## Examples of Shiny
The [Shiny Gallery](https://shiny.posit.co/r/gallery/) which includes dashboards as well as parts (widgets) that can be added.
And from healthcare:
[![](https://github.com/traffordDataLab/imd19/raw/master/screenshot.png){fig-alt="Screenshot of the Indices of Deprivation 2019 dashboard from Trafford Data lab"}](https://trafforddatalab.shinyapps.io/imd19)
## Mental Health Surge Model app
[![](img/mental_health_modelling.PNG){fig-alt="Screenshot of Mental Health Modelling app from The Strategy Unit used to estimate the impacts of COVID-19 on mental health services in England"}](https://strategyunit.shinyapps.io/MH_Surge_Modelling/)
## Patient Feedback text mining app
[![](img/screenshot-pxtextmining.PNG){fig-alt="Screenshot of Patient Text Mining app from Nottinghamshire Healthcare NHS Foundation Trust (via funding from NHS England)"}](https://cdu-data-science-team.github.io/pxtextmining/)
## The future of Shiny - is here!
As RStudio renamed to Posit in 2022 to extend their language association beyond R, so they are also working on extending Shiny apps
::: {.incremental}
- To be compatible with the power of [Python](https://shiny.posit.co/py/)
- To publish without a server using [Shinylive](https://jcheng5.github.io/posit-conf-2023-shinylive/#/title-slide)
- An example is this [app](https://matt-dray.github.io/govspeakify-tables/) that converts a table to Govspeak Markdown, the format required for publishing reports by the UK's government from Matt Dray's [blog](https://www.rostrum.blog/posts/2023-10-08-govspeakify-tables/)
:::
## End session
### Acknowledgements
[Mastering Shiny](https://mastering-shiny.org/basic-app.html) by Hadley Wickham
[Beginners course by Chris Beeley](https://github.com/ChrisBeeley/shiny_beginners/tree/main) aimed at relatively novice R users
[Shiny workshop for NHS-R Community](https://www.youtube.com/watch?v=wEYaeltxlys&list=PLXCrMzQaI6c1Na7BE18OsWtE1WKqrclNn&index=27)
[Shiny workshop materials](https://github.com/nhs-r-community/shiny-training) on the NHS-R Community GitHub.
[Building Web Apps with R Shiny](https://debruine.github.io/shinyintro/first-app.html) from [PsyTeachR](https://psyteachr.github.io/)