-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.qmd
326 lines (213 loc) · 7.28 KB
/
index.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
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
---
title: "Empowering Medical Insight <br> through an <br> Interactive R Shiny"
author: "Dewi Amaliah"
format:
revealjs:
title-slide-attributes:
data-background-image: images/bg.png
data-background-size: cover
transition: none
smaller: true
controls: true
slide-number: false
chalkboard:
buttons: false
preview-links: auto
logo: images/siena_logo.png
hide-from-titleSlide: "all"
theme: styles/slide-styles.scss
css: styles/additional-styles.css
editor: visual
---
## Agenda
- Brief introduction to R Shiny
- Importance of interactive tools in medical research
- Examples of applications in biostatistics and healthcare
- Case study on "Heart Failure Prediction"
- Quiz
## Let's Put This into Context
![](images/context.png)
## What is Web Application?
::: callout-note
## Definition
- A web application (or web app) is an application that can be accessed through a web browser.
- Needs skills on javascript, html, or css.
:::
::: fragment
::: callout-note
## Goals
- Connect people and data;
- Make systems playful;
- Personalise the view;
- Reduce cognitive load.
[^1]
:::
:::
[^1]: [Source: Communicating data with interactive apps, Lecture Notes, Monash University](https://cwd.numbat.space/lectures/lecture-03.html#/etc5523-title)
## What is R Shiny?
::: columns
::: {.column width="20%"}
![](images/shiny.png){width="219"}
:::
:::
::: columns
::: {.column width="80%"}
- Shiny ([Chang, et.al., 2023](https://CRAN.R-project.org/package=shiny)) is an R packages that support web app development using R.
- No HTML/css/javascript required.
- Enable data analysis in an interactive manners.
- As it is developed using R, it can be supported by other R packages.
- Can be hosted and accessed online.
:::
:::
## Why it is important?
### Especially in Biostatistics & Healthcare
::: callout-note
## Interactive data analysis and visualization enable:
- Monitoring and analysis -\> quality improvement and performance monitoring
- Decision support systems
- Research and collaboration
- Patient engagement and education
:::
## Shiny App in the Wild (1)
- [Vaccine Queue Simulator](https://cbdrh.shinyapps.io/queueSim/) by Mark Hanly, Oisín Fitzgerald, and Tim Churches
- Decision support system, i.e., planning for healthcare capacity
![](images/vaccine_simulator.png)
## Shiny App in the Wild (2)
- [Healthdown](https://hoga.shinyapps.io/healthdown/) by Peter Gandenberger and Andreas Hofheinz
- Monitoring and analysis, i.e., comparing health metrics geographically
![](images/healthdown.png)
## Shiny App in the Wild (3)
- [ReviewR](https://thewileylab.shinyapps.io/ReviewR/) by Laura Wiley, Luke Rasmussen, and David Mayer
- Research and collaboration, i.e., connect to Electronic Health Record (EHR) data and doing data analysis
![](images/reviewR.png)
## Shiny App in the Wild (4)
- [Genome browser](https://gallery.shinyapps.io/genome_browser/) by ICGC Data Portal
- Research and collaboration, i.e., genome visualization
![](images/genome.png)
## Shiny App in the Wild (5)
- [Nutrition calculator](https://yihanw.shinyapps.io/Recipe_Nutrition/) by Yihan Wu
- Engagement and education, i.e., calculate nutrition for recipes
![](images/nutrition.png)
## Shiny's element
::: panel-tabset
## Overview
```{r, eval=FALSE, echo = TRUE}
# load the shiny package
library(shiny)
# define user interface object
ui <- fluidPage()
# define server function
server <- function(input, output) { }
# call to shinyApp() which returns a Shiny app object from an
# explicit UI/server pair
shinyApp(ui = ui, server = server)
```
## Client & Server Communication
![Source: Communicating data with interactive web apps, Lecture Notes, Monah University](images/serverclient.png)
:::
## Shiny's UI
::: columns
::: {.column width="60%"}
**Input element**
- Interact with user by modifying the input values. Can be text, number, date, file, etc.
- Input has an id to communicate with server
**Output element**
- Display operation done in server
- Can be a plot, table, text
**Layout**
- Organize the layout of the app (panels or tabs)
- Using themes
- Explanatory text
:::
::: {.column width="40%"}
```{r , eval=FALSE, echo = TRUE}
# load the shiny package
library(shiny)
# define the user interface object with the appearance of the app
# layout is fluidPage
ui <- fluidPage(
title("Create your Histogram"),
# input type
numericInput(inputId = "n", label = "Sample size", value = 25),
# output type
plotOutput(outputId = "hist")
)
```
:::
:::
## Input Options
![Example of input type in Shiny](images/inputs.png)
## Output Options
![List of output options in Shiny](images/outputs.png)
## Layout
::: panel-tabset
## Basic layout
![Layout options on Shiny](images/basic_layout.png)
## Tab Panel
![Tabset options on Shiny](images/tabpanel.png)
## Themes
![Themes option on Shiny. See also: https://rstudio.github.io/shinythemes/](images/themes.png){width="375"}
```{r, eval = FALSE, echo = TRUE}
library(shinythemes)
shinyApp(
ui = fluidPage(theme = shinytheme("united"),
...
),
server = function(input, output) { }
)
```
:::
## Shiny's Server
::: columns
::: {.column width="60%"}
**Operation/ Calculation**
- Where all of the operation or calculation done
- Takes all of the user inputs using the input id -\> reactive element
**Output element**
- Render the output to be displayed on output
- Pair with the output id on the UI side
:::
::: {.column width="40%"}
```{r , eval=FALSE, echo = TRUE}
# create the histogram output
server <- function(input, output) {
output$hist <- renderPlot({
hist(rnorm(input$n))
})
}
```
:::
:::
## Reactivity
- `reactiveValues` creates your own reactive values
- `isolate` prevents reactions
- `reactive` caches its value to reduce computation and notifies its dependencies when it has been invalidated
- `observe` runs code when any reactive elements within it changes
- `observeEvent` runs code when the first argument changes
## Deploy your App
- Share your codes (app.R) and running it on R studio
- Host online for free at shinyapps.io
- Use [`shinylive`](https://medium.com/@rami.krispin/deploy-shiny-app-on-github-pages-b4cbd433bdc#:~:text=Shinylive%20is%20a%20serverless%20version%20of%20Shiny%2C%20which%20enables%20running,recommend%20watching%20this%20talk!)
- Personal server
## Hands On
::: callout-note
## Goal
Create a Shiny app to do health screening (BMI, hypertension, diabetes, and 10-year cardiovascular risk)
:::
::: callout-note
## Data
The data is from the patient based on several screening/ lab test.
:::
::: callout-note
## Tutorial
You can access the tutorial [here](https://github.com/Dewi-Amaliah/its_shiny_slide/blob/main/tutorial.pdf).
:::
## Quiz
![](https://i.gifer.com/877c.gif){fig-align="center"}
1st and 2nd winner will receive IDR 50k each from Siena
## Moving Forward
- Learn more ([Mastering shiny (e-book)](https://mastering-shiny.org/), [tutorial](https://shiny.posit.co/r/getstarted/shiny-basics/lesson1/index.html))
- Can also be developed using Python
- [Cheatsheet for Shiny](https://shiny.posit.co/r/articles/start/cheatsheet/)
- [Debugging Shiny](https://shiny.posit.co/r/articles/improve/debugging/)
- [More examples](https://shiny.posit.co/r/gallery/)