-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquarto-dashboard-example.qmd
181 lines (133 loc) · 3.73 KB
/
quarto-dashboard-example.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
---
title: Super cool idea for tinyshiny replacement
subtitle: A one off html embed you do not have to maintain from release to release
format: dashboard
layout: custom
---
```{r}
#| output: false
library(readr)
library(dplyr)
library(tidyr)
library(plotly)
library(downloadthis)
data = read_csv("example-data.csv")
nat_table <- data %>%
filter(geographic_level == "National" & time_period == "202122") %>%
select(school_type, perm_excl, perm_excl_rate, suspension, susp_rate)
la_data <- data %>%
filter(geographic_level == "Local authority") %>% select(time_period, la_name, school_type, perm_excl_rate, susp_rate) %>%
group_by(la_name) %>%
pivot_wider(names_from = time_period,values_from=c(perm_excl_rate,susp_rate))
```
::: {.panel-tabset}
## Example tab 1
::: {layout="[ [2,3], [1] ]"}
```{r}
knitr::kable(nat_table)
```
```{r}
#| fig-width: 10
#| fig-height: 8
nat_table %>%
plot_ly(
type = 'bar',
x = ~school_type,
y = ~perm_excl_rate
) %>% config(displayModeBar = F)
```
:::
## Example tab 2
```{r}
#a function to set drop down options for number of filter categories
genDropdown <- function(NameList) {
outlist <- list(list(
method = "restyle",
args=list("transforms[0].value", NameList[1]),
label = NameList[1]
))
for(i in 2:length(NameList)) {
item <- list(list(
method = "restyle",
args=list("transforms[0].value", NameList[i]),
label = NameList[i]
))
outlist <- c(outlist,item)
}
return(outlist)
}
#plot output
la_data %>%
plot_ly(
type = 'scatter',
x = ~susp_rate_202021,
y = ~susp_rate_202122,
text = ~la_data$la_name,
hoverinfo = 'text',
mode = 'markers',
transforms = list(
list(
type = 'filter',
target = ~school_type,
operation = '=',
value = unique(la_data$school_type)[1]
)
)) %>% layout(
updatemenus = list(
list(
type = 'dropdown',
active = 0,
buttons = genDropdown(unique(la_data$school_type)) # this does it via generic function, commented bit below shows longer way
# buttons = list(
# list(method = "restyle",
# args = list("transforms[0].value", unique(la_data$school_type)[1]),
# label = unique(la_data$school_type)[1]),
# list(method = "restyle",
# args = list("transforms[0].value", unique(la_data$school_type)[2]),
# label = unique(la_data$school_type)[2]),
# list(method = "restyle",
# args = list("transforms[0].value", unique(la_data$school_type)[3]),
# label = unique(la_data$school_type)[3]),
# list(method = "restyle",
# args = list("transforms[0].value", unique(la_data$school_type)[4]),
# label = unique(la_data$school_type)[4])
# )
)
)
) %>%
config(displayModeBar = F)
# Note there's 12 values ignored, I assume because of missing or invalid data
```
## Example tab 3
You can do data downloads too, though whenever I include them it breaks the plotly formatting for some reason
```{r}
#| output: false
la_data %>%
download_this(
output_name = "la_year_on_year_comparison",
output_extension = ".csv",
button_label = "Download data",
button_type = "warning",
has_icon = TRUE,
icon = "fa fa-save",
csv2 = FALSE
)
```
```{r}
#| output: false
nat_table %>%
download_this(
output_name = "la_year_on_year_comparison",
output_extension = ".csv",
button_label = "Download data",
button_type = "warning",
has_icon = TRUE,
icon = "fa fa-save",
csv2 = FALSE
)
```
<details>
<summary>You can do details components too</summary>
contents
</details>
:::