globalVariables("bl")
#' reacttable Tabelle mit Fallzahlen
#'
#' Erzeuge eine Tabelle von [reactable::reactable()] mit absoluten und
#' relativen Fallzahlen
#' @export
table_react <- function() {
dc <- data_corona()
bezirke <- dc$bezirke
table_data <- merge(bezirke, coronaAT::geo_bez) %>%
dplyr::mutate(bl = substring(id, 1, 1), id = NULL, lon = NULL, lat = NULL, area = NULL,
ratio = freq/population * 100000) %>%
dplyr::mutate(bl = c("Burgenland", "K\u00e4rnten", "Nieder\u00f6sterreich", "Ober\u00f6sterreich",
"Salzburg", "Steiermark", "Tirol", "Vorarlberg", "Wien")[as.numeric(bl)])
reactable::reactable(
table_data,
groupBy = "bl", highlight = TRUE, wrap = FALSE,
columns = list(
bl = reactable::colDef(footer = "Gesamt", name = "Bundesland"),
bezirk = reactable::colDef(filterable = TRUE, name = "Bezirk", aggregate = "unique",
footer = function(values){ paste(length(values), "Bezirke") }),
freq = reactable::colDef(
aggregate = "sum",
name = "Best\u00e4tigte F\u00e4lle", format = reactable::colFormat(separators = TRUE),
footer = function(values) format(sum(values), big.mark = ",")
),
population = reactable::colDef(
aggregate = "sum", name = "Einwohner",
format = reactable::colFormat(separators = TRUE),
footer = function(values) format(sum(values), big.mark = ",")
),
ratio = reactable::colDef(
name = "F\u00e4lle pro 100 000 EW",
format = reactable::colFormat(digits = 2),
aggregate = reactable::JS(
'function(values, rows){
let pop = 0;
let freq = 0;
for (i = 0; i < values.length; i++) {
pop = pop + rows[i]._original.population
freq = freq + rows[i]._original.freq
}
return freq/pop*100000;
}'),
style = function(value) {
if (value[1] < 20) {
color <- "#008000"
} else if (value[1] >= 100) {
color <- "#e00000"
} else {
color <- "#777"
}
list(color = color)
},
footer = round(sum(table_data$freq)/sum(table_data$population)*100000, 2)
)
),
defaultColDef = reactable::colDef(footerStyle = list(fontWeight = "bold"))
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.