-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.R
695 lines (539 loc) · 26.9 KB
/
server.R
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
server <- function(input, output, session) {
observeEvent(input$selected_language, {
update_lang(input$selected_language, session)
})
setBookmarkExclude(c("katalog_rows_current", "plotAudio_rows_all", "sozialdaten", "plotAudio_rows_current", "plotAudio_cell_clicked", "plotAudio_state"))
# Reactive function for the variable
variable <- reactive({
req(input$variable)
input$variable
})
# Reactive function for the variable_name
variable_name <- reactive({
variables %>%
dplyr::filter(variable == variable()) %>%
dplyr::select(input_choice)
})
# Reactive function for the selection
selection <- reactive({
selection <- variables %>%
filter(variable == variable()) %>%
pull(selection) %>%
as.character() %>%
as.vector()
selection <- strsplit(selection, " ")[[1]]
return(selection)
})
# Reactive function to load the appropriate Google table based on the selected variable
google_df <- reactive({
# Obtain the Google table name associated with the selected variable
google_df_name <- variables %>%
filter(variable == variable()) %>% pull(google_df)
# Load and return the QS file associated with the table name
qread(paste0("./raw_tables/", google_df_name, ".qs"))
})
# Reactive function to pivot the Google table to a longer format and filter by selected variants
longer_google_df <- reactive({
google_df() %>%
# filter only data from Luxembourg
filter(Kanton != "") %>%
# Pivot the table to a longer format
pivot_longer(cols = variable(),
names_to = "variable",
values_to = "variants") %>%
# Filter rows based on selected variants
filter(variants %in% selection())
})
# Define the reactive function to determine the most frequent variant
most_frequent_variant <- reactive({
# Get the counts of each variant
input_data <- google_df() %>%
dplyr::select(variable()) %>%
dplyr::filter_at(vars(variable()), ~ . != "FALSE")
counts <- table(input_data)
# Get the name of the variant with the highest count
names(counts)[which.max(counts)]
})
# Reactive function to prepare data for maps
prepare_data <- reactive({
# Get the longer_google_df
longer_google_df <- longer_google_df()
# Determine the base polygon (canton or commune) based on the number of participants per item
geo_type <- if (nrow(longer_google_df) <= 2200) "Kanton" else "Gemeng"
#geo_type <- input$selected_geo_type
# Pivot the table and add a 'geo_type' column
longer_google_df <- longer_google_df %>%
pivot_longer(cols = geo_type,
names_to = "geo_type",
values_to = "geo_name") %>%
mutate(variants = factor(variants, ordered = TRUE))
# Calculate the total and frequency of each variant
variants_total <- longer_google_df %>%
filter(geo_type == geo_type) %>%
group_by(geo_name, variable(), variants) %>%
count() %>%
group_by(geo_name, variable()) %>%
mutate(total = sum(n)) %>%
mutate(freq = n / total)
# Add the color column based on the selection
color <- color_palette
color_column <- tribble(~variants, ~color,
selection()[1], color[1],
selection()[2], color[2],
selection()[3], color[3],
selection()[4], color[4],
selection()[5], color[5],
selection()[6], color[6],
selection()[7], color[7],
selection()[8], color[8])
variants_total <- left_join(variants_total, color_column, copy = TRUE)
# Join the data with the corresponding geographical data (cantons_df or communes_df)
df <- if (geo_type == "Kanton") {
inner_join(cantons_df, variants_total, by = c("id" = "geo_name"), multiple = "all")
} else {
inner_join(communes_df, variants_total, by = c("id" = "geo_name"), multiple = "all")
}
return(list("dataset" = df, "geo_type" = geo_type))
})
# Reactive function to prepare data for maps with age information
prepare_data_age <- reactive({
# Get the longer_google_df
longer_google_df <- longer_google_df()
# Determine the base polygon (canton or commune) based on the number of participants per item
geo_type <- if (nrow(longer_google_df) <= 2200) "Kanton" else "Gemeng"
# Recode age, pivot the table, and add a 'geo_type' column
longer_google_df <- longer_google_df %>%
mutate(Alter = case_match(Alter,
c("≤ 24", "25 bis 34") ~ "jonk",
c("35 bis 44", "45 bis 54") ~ "mëttel-al",
c("55 bis 64", "65+") ~ "eeler")
) %>%
mutate(Alter = factor(Alter, levels = c("eeler", "mëttel-al", "jonk"))) %>%
pivot_longer(cols = geo_type,
names_to = "geo_type",
values_to = "geo_name") %>%
mutate(variants = factor(variants, ordered = TRUE))
# Calculate the total and frequency of each variant, grouped by age
variants_total <- longer_google_df %>%
filter(geo_type == geo_type) %>%
group_by(Alter, geo_name, variable(), variants) %>%
count() %>%
group_by(Alter, geo_name, variable()) %>%
mutate(total = sum(n)) %>%
mutate(freq = n / total)
#saveRDS(variants_total, "test.rds")
# Add the color column based on the selection
color <- color_palette
color_column <- tribble(~variants, ~color,
selection()[1], color[1],
selection()[2], color[2],
selection()[3], color[3],
selection()[4], color[4],
selection()[5], color[5],
selection()[6], color[6],
selection()[7], color[7],
selection()[8], color[8])
variants_total <- left_join(variants_total, color_column, copy = TRUE)
# Join the data with the corresponding geographical data (cantons_df or communes_df)
df <- if (geo_type == "Kanton") {
inner_join(cantons_df, variants_total, by = c("id" = "geo_name"), multiple = "all")
} else {
inner_join(communes_df, variants_total, by = c("id" = "geo_name"), multiple = "all")
}
return(list("dataset" = df, "geo_type" = geo_type))
})
# Reactive function to prepare data for detailed variant maps
prepare_data_variant_maps <- reactive({
# Get the longer_google_df
longer_google_df <- longer_google_df()
# Determine the base polygon (canton or commune) based on the number of participants per item
geo_type <- if (nrow(longer_google_df) <= 200) "Kanton" else "Gemeng"
# Pivot the table and add a 'geo_type' column
longer_google_df <- longer_google_df %>%
pivot_longer(cols = geo_type,
names_to = "geo_type",
values_to = "geo_name") %>%
mutate(variants = factor(variants, ordered = TRUE))
# Calculate the total and frequency of each variant
variants_total <- longer_google_df %>%
filter(geo_type == geo_type) %>%
group_by(geo_name, variable(), variants) %>%
count() %>%
group_by(geo_name, variable()) %>%
mutate(total = sum(n)) %>%
mutate(freq = n / total)
# Add the color column based on the selection
color <- color_palette
color_column <- tribble(~variants, ~color,
selection()[1], color[1],
selection()[2], color[2],
selection()[3], color[3],
selection()[4], color[4],
selection()[5], color[5],
selection()[6], color[6],
selection()[7], color[7],
selection()[8], color[8])
variants_total <- left_join(variants_total, color_column, copy = TRUE)
# Join the data with the corresponding geographical data (cantons_df or communes_df)
df <- if (geo_type == "Kanton") {
inner_join(cantons_df, variants_total, by = c("id" = "geo_name"), multiple = "all")
} else {
inner_join(communes_df, variants_total, by = c("id" = "geo_name"), multiple = "all")
}
return(list("dataset" = df, "geo_type" = geo_type))
})
# reactive function to get the card for the info on a variable
card_header_title <- reactive({
variables %>%
filter(variable == variable()) %>%
dplyr::pull(map_category) %>%
first()
})
output$iwwersiicht_variabel <- renderUI({
unilu_card(
paste0(i18n$t("Phenomeen aus dem Beräich '"), i18n$t(card_header_title()), "'"),
HTML(
paste0(
tags$ul(class="list-unstyled",
tags$li(tags$span(i18n$t("Variabel: "), class="fw-bold"), variable_name()),
tags$li(tags$span(i18n$t("Offrokontext: "), class="fw-bold"),variables %>% filter(variable == variable()) %>% dplyr::select(item_text)),
tags$li(tags$span(i18n$t("Analyséiert Varianten: "), class="fw-bold"), paste(selection(), collapse = ", ")),
tags$li(tags$span(i18n$t("Heefegst Variant: "), class="fw-bold"), em(most_frequent_variant())),
tags$li(tags$span(i18n$t("Schnëssen-Item: "), class="fw-bold"), variables %>% filter(variable == variable()) %>% dplyr::select(item_number)),
tags$li(tags$span(i18n$t("Ausgewäert Realiséierungen: "), class="fw-bold"), nrow(longer_google_df()))
)
)
)
)
})
# Plot overall distribution of variants #
output$plotFreqVariants <- renderPlot({
plot_freq_variants(data = google_df(), variable = variable(), selection = selection())
})
### Iwwerbléckskaart #
output$Iwwerbléckskaart <- renderGirafe({
lsa_map_number <- variables %>% filter(variable == variable()) %>% pull(lsa_map_number) %>% as.character()
# pull item number from tribble
item_number <- variables %>% filter(variable == variable()) %>% pull(item_number) %>% as.character()
# pull item text from tribble
item_text <- variables %>% filter(variable == variable()) %>% pull(item_text) %>% as.character()
if(file.exists(paste0("./overview_maps/Iwwerbleckskaart_", variable(), ".qs"))) {
qread(paste0("./overview_maps/Iwwerbleckskaart_", variable(), ".qs"))
}
else {
print(paste(variable(),": Iwwerbléckskaart gëtt generéiert"))
make_summary_plot(data = prepare_data()[["dataset"]], lsa_map_number = lsa_map_number,
selection= selection(), color_num = length(selection()), map_title = variable(), item_number,
item_text, geo_type = prepare_data()[["geo_type"]])
}
})
### Iwwerbléckskaarte per age #
output$Iwwerbléckskaart_no_alter <- renderPlot({
lsa_map_number <- variables %>% filter(variable == variable()) %>% pull(lsa_map_number) %>% as.character()
# pull item number from tribble
item_number <- variables %>% filter(variable == variable()) %>% pull(item_number) %>% as.character()
# pull item text from tribble
item_text <- variables %>% filter(variable == variable()) %>% pull(item_text) %>% as.character()
# if(file.exists(paste0("./overview_maps/Iwwerbleckskaarten_Alter_", variable(), ".qs"))) {
# qread(paste0("./overview_maps/Iwwerbleckskaarten_Alter_", variable(), ".qs"))
# }
# else {
print(paste(variable(),": Eenzel Alterskaaarten gi generéiert"))
make_summary_plot_age(data = prepare_data_age()[["dataset"]], lsa_map_number = lsa_map_number,
selection= selection(), color_num = length(selection()), map_title = variable(), item_number,
item_text, geo_type = prepare_data()[["geo_type"]])
# }
})
#####################
### Variantekaarten #
#####################
# separate plot function for download link
myplot <- reactive({
# function to generalte a df containing the individual maps for the selected variants
# make_plot() is the actual drawing function to create one map
# each map is stored in plots$plots
all_maps <- function(data) {
plots <- data %>%
group_by(variants, color) %>%
nest() %>%
drop_na() %>%
mutate(plots = pmap(list(variable = variants,
dataset = data,
color = color),
make_plot))
# using now patchwork - smaller
p <- wrap_plots(plots$plots, ncol = 3)
rm(plots, data)
# save map as qs
#print("saving Variantekaarten")
#qsave(p, file = paste0("Variantekaarten_", variable(), ".qs"))
#ggsave(plot = p, filename = paste0("variantekaart_", ".pdf"), units = "cm", width = 22)
return(p)
}
# if qs file already exist, display it (faster); if not, create the map (slower)
# if(file.exists(paste0("Variantekaarten_", variable(), ".qs"))) {
# print("lokal Variantekaarten")
# qread(paste0("Variantekaarten_", variable(), ".qs"))
# }
# else {
print(paste(variable(),": Varianteaarte gi generéiert"))
all_maps(data = prepare_data_variant_maps()$dataset)
# }
})
# plot function
output$Variantekaarten <- renderPlot({
myplot()
})
# determine height by number of variants in plot
plotHeight <- reactive((700 + 20) * (ceiling(length(selection()) / 3 )) - 20 - 200)
# render plot as UI (not plot!) to maintain height attribute
output$plot.ui <- renderUI({
plotOutput("Variantekaarten", height = plotHeight())
})
# create download button for Variantekaarten
output$downloadData <- downloadHandler(
filename = function() {
paste("Variantekaarten_", variable(), Sys.Date(), ".png", sep="")
},
content = function(file) {
# TODO: size attributes not optimal
png(file=file, height = plotHeight(), width = 960)
# call separate plot function from above
plot(myplot())
dev.off()
}
)
output$plotAlter <- renderPlot({
# variableFonInput <- input$kaart
# variable <- variableFonInput
#
# # pull variant selection list from tribble
# selection <- variables %>% filter(variable == variableFonInput) %>% pull(selection) %>% as.character() %>% as.vector()
# selection <- strsplit(selection, " ")[[1]]
caption = ""
plot_social_categories(data = google_df(), Alter, variable = variable(), selection = selection(), caption = caption)
})
# plot function Geschlecht
output$plotGeschlecht <- renderPlot({
plot_social_categories(data = google_df(), Geschlecht, variable = variable(), selection = selection())
})
# plot function Dialektgebiet
output$plotDialektgebiet <- renderPlot({
caption = ""
plot_social_categories(data = google_df(), Dialektgebiet, variable = variable(), selection = selection(), caption = caption)
})
# reactive function for google data for mixed model
data_regression <- reactive({
max_var <- most_frequent_variant()
title = paste("Heefegst Variant/Referenzvariant:", max_var)
var <- variable()
data <- google_df() %>%
filter(!!sym(var) %in% selection()) %>%
# add a new variable temp2 which is 1 for the most frequent variant of the reactive 'variable()', 0 otherwise
mutate(temp_variable = ifelse(!!sym(var) == max_var, 1, 0)) %>%
# add a new variable kompetenz_däitsch, based on `Kompetenz am Däitschen` rescaled from 0 to 1 using scales::rescale()
mutate(`Kompetenz am Däitschen` = scales::rescale(as.numeric(`Kompetenz am Däitschen`), to = c(0, 1))) %>%
mutate(`Kompetenz am Franséischen` = scales::rescale(as.numeric(`Kompetenz am Franséischen`), to = c(0, 1))) %>%
# relevel factor Dialektgebiet to "Zentrum" (reference level)
mutate(Dialektgebiet = relevel(Dialektgebiet, ref = "Zentrum"))
#str(data)
return(list(data = data, title = title))
})
# plot function Sprooch & Educatiouns-Index
output$plotLangEduIndex <- renderPlot({
caption = i18n$t(paste("Dësen Index kombinéiert dat sproochlecht mat dem Ausbildungskapital:\n
Kompetenz am Däitschen (25%), Kompetenz am Franséischen (40%), Ausbildung (35%).\n
Den Index rangéiert tëschent 0 an 1 (= maximaalt Kapital, i.e. béid Sproochkompetenzen maximal, Ausbildung: Universitéit/Fachhéichschoul)"))
plot_social_categories(data = google_df() %>%
# only Mammesproochler
filter(Mammesprooch == "Jo"),
`Sprooch & Educatioun-Index`, variable = variable(), selection = selection(), caption = caption)
})
# run a logistic regression
lmodel <- reactive({
#glm(as.formula(paste("temp_variable ~", input$selectedVariable)), family = "binomial", data = data_regression()$data)
glm(as.formula(paste("temp_variable ~ `Kompetenz am Däitschen` + `Kompetenz am Franséischen` + Alter + Geschlecht")),
family = "binomial",
data = data_regression()$data)
# für multinomial regression
# nnet::multinom(as.formula(paste(variable(), " ~ langEduIndex_raw + Alter + Geschlecht + Dialektgebiet")),
# data = data_regression()$data)
# data <- data_regression()$data
# model <- glmulti::glmulti(temp_variable ~ `Kompetenz am Däitschen` + `Kompetenz am Franséischen` + Alter + Geschlecht + Dialektgebiet,
# data = data,
# level = 1,
# method = "d",
# crit = "aicc",
# family = "binomial",
# fitfunction = glm,
# confsetsize = 0.95,
# plotty = FALSE)
#
# model@objects[[1]]
# print(summary(model@objects[[1]]))
})
coeffs <- reactive({
broom::tidy(lmodel()) %>%
dplyr::filter(!grepl("Alter.Q|Alter.C|Alter\\^4|Alter\\^5|Ausbildung.Q|Ausbildung.C|Ausbildung\\^4|Ausbildung\\^5", term)) %>%
dplyr::select(parameter = term, est = estimate, se = std.error, z = statistic, p = p.value) %>%
# für multinomial regression
#dplyr::select(parameter = term, est = estimate, se = std.error, z = statistic, p = p.value, Response = y.level) %>%
# Create pretty.parameter and signif_labels columns
mutate(parameter = fct_reorder(parameter, est)) %>%
mutate(signif_labels = ifelse(p < 0.001, "***", ifelse(p < 0.01, "**", ifelse(p < 0.05, "*", ""))))
})
# Output the LM
output$textLModel <- renderUI({
HTML(sjPlot::tab_model(lmodel(),
rm.terms = c("Alter.C", "Alter.Q", "Alter^4", "Alter^5", "Ausbildung.C", "Ausbildung.Q", "Ausbildung^4", "Ausbildung^5"),
p.style = "scientific_stars",
title = data_regression()$title,
dv.labels = most_frequent_variant()
)$knitr)
})
output$plotLModel <- renderPlot({
# see: https://keikcaw.github.io/visualizing-logistic-regression/Intro.html#Introduction:_Just_tell_me_%E2%80%9Cthe%E2%80%9D_effect
# Define a named vector for colors
color_mapping <- c("Positiv" = "#0571B0",
"Net signifikant" = "gray",
"Negativ" = "#CA0020")
# Specify Roboto as the font family
theme_set(theme_minimal() +
theme(
axis.title.x = element_text(size = 14, family = "Lato"), # X-axis title font
axis.title.y = element_text(size = 14, family = "Lato"), # Y-axis title font
axis.text.x = element_text(size = 14, family = "Lato"), # X-axis labels font
axis.text.y = element_text(size = 14, family = "Lato"), # Y-axis labels font
plot.title = element_text(size = 14, family = "Lato") # Plot title font
))
coeffs() %>%
filter(parameter != "(Intercept)") %>%
mutate(
pretty.parameter = fct_reorder(parameter, est),
lower.95 = est + (qnorm(0.025) * se),
lower.50 = est + (qnorm(0.25) * se),
upper.50 = est + (qnorm(0.75) * se),
upper.95 = est + (qnorm(0.975) * se),
signif = case_when(p > 0.05 ~ i18n$t("Net signifikant"),
est > 0 ~ i18n$t("Positiv"),
est < 0 ~ i18n$t("Negativ")),
signif = fct_relevel(signif, i18n$t("Positiv"),
i18n$t("Net signifikant"),
i18n$t("Negativ"))) %>%
ggplot(aes(x = pretty.parameter, color = signif)) +
geom_linerange(aes(ymin = lower.95, ymax = upper.95), size = 1) +
geom_linerange(aes(ymin = lower.50, ymax = upper.50), size = 2) +
geom_point(aes(y = est), size = 4) +
geom_hline(yintercept = 0) +
scale_y_continuous(
breaks = c(-1, 0, 1), #<<
labels = c(i18n$t("← Manner"), #<<
i18n$t("Gläich"), #<<
i18n$t("Méi →")) #<<
) +
scale_color_manual(
"",
values = color_mapping
) +
geom_text(aes(x = pretty.parameter, y = upper.95, label = signif_labels), vjust = -0.5, size = 6) +
labs(x = "", y = i18n$t("Warscheinlechkeet vum Gebrauch\nvun der Variant"),
title = paste0(data_regression()$title, i18n$t("\n\nGeschate Relatioun tëscht soziale Facteuren an der\nWarscheinlechkeet fir de Gebrauch vun der Variant"))) +
coord_flip(clip = "off")
})
# plot Ausbildung
output$plotAusbildung <- renderPlot({
caption = ""
plot_social_categories(data = google_df(), Ausbildung, variable = variable(), selection = selection(), caption = caption)
})
# plot function Kompetenz D
output$plotKompetenzD <- renderPlot({
caption = i18n$t("Baséiert op Selbstaschätzung. 1 = bal guer keng Kompetenz, 7 = perfekt Kompetenz. \nFir d'Interpretatioun si just d'Stufe vu 5 bis 7 reliabel.")
plot_social_categories(data = google_df(), `Kompetenz am Däitschen`, variable = variable(), selection = selection(), caption = caption)
})
# plot function Kompetenz F
output$plotKompetenzF <- renderPlot({
caption = i18n$t("Baséiert op Selbstaschätzung. 1 = bal guer keng Kompetenz, 7 = perfekt Kompetenz. \nFir d'Interpretatioun si just d'Stufe vun 3 bis 7 reliabel.")
plot_social_categories(data = google_df(), `Kompetenz am Franséischen`, variable = variable(), selection = selection(), caption = caption)
})
# plot function Sproochekompetenz
output$plotSproochekompetenz <- renderPlot({
caption = i18n$t("Gemëttelt aus Kompetenz D + F.")
plot_social_categories(data = google_df(), `Sproochekompetenz`, variable = variable(), selection = selection(), caption = caption)
})
# plot function Mammesprooch
output$plotMammesprooch <- renderPlot({
caption = ""
plot_social_categories(data = google_df(), `Mammesprooch`, variable = variable(), selection = selection(), caption = caption)
})
# plot function Aflëss
output$plotAfloss <- renderPlot({
caption = i18n$t("Baséiert op Selbstaschätzung.")
plot_social_categories(data = google_df(), `Sproochlech Aflëss`, variable = variable(), selection = selection(), caption = caption)
})
# plot function Urbanisatioun
output$plotUrbanisatioun <- renderPlot({
caption = i18n$t("Baséiert op dem 'Degree of Urbanisation' (DEGRUBA).\n1 = staark urbaniséiert (= d'Stad Lëtzebuerg), 3 = wéineg urbaniséiert\nSource: STATEC (https://statistiques.public.lu/en/themes/population-emploi.html)")
plot_social_categories(data = google_df(), Urbanisatioun, variable = variable(), selection = selection(), caption = caption)
})
# plot function Awunner_km2
output$plotAwunner <- renderPlot({
caption = ""
plot_social_categories(data = google_df(), Awunner_km2, variable = variable(), selection = selection(), caption = caption)
})
# plot function Indice socio-économique
output$plotIndex <- renderPlot({
caption = i18n$t("Baséiert op dem 'Indice socio-économique' pro Gemeng.\n\nSource: STATEC (https://statistiques.public.lu/dam-assets/catalogue-publications/bulletin-Statec/2017/bulletin-2-17.pdf)")
plot_social_categories(data = google_df(), `Indice socio-économique`, variable = variable(), selection = selection(), caption = caption)
})
# plot function Immigratioun
output$plotImmigratioun <- renderPlot({
caption = i18n$t("Prozentzuel vun Net-Lëtzebuerger pro Gemeng\nSource: STATEC: https://data.public.lu/en/datasets/population-de-residence-habituelle-par-commune-et-nationalite-au-1er-fevrier-2011/")
plot_social_categories(data = google_df(), Immigratioun, variable = variable(), selection = selection(), caption = caption)
})
# plot inference decision tree
output$plotTree <- renderPlot({
plot_decision_tree(data = google_df(), variable = variable(), selection = selection())
})
# plot variable importance from random forest
output$plotVariableImportance <- renderPlot({
if(file.exists(paste0(variable(), "_VariableImportance.qs"))) {
print("lokal VariableImportance")
qread(paste0(variable(), "_VariableImportance.qs"))
}
else {
print(i18n$t("VariableImportance gëtt generéiert"))
plot_VariableImportance(data = google_df(), variable = variable(), selection = selection())
}
})
# plot function Audio
output$plotAudio <- renderDT({
plot_datatable(data = google_df(), variable = variable())
})
## Plot Kaartekatalog
output$katalog <- renderDT({
datatable(variables %>%
dplyr::select(Variabel = input_choice, Varianten = selection, Kategorie = map_category, Offrokontext = item_text,
variable, Item = item_number, `LSA-Kaart` = lsa_map_number) %>%
# Links for bookmarks
# shinyapps
mutate(Variabel = paste0("<a href=", SERVER, "?_inputs_&sidebar=true&nav=%22Kaarten%22&variable=%22", variable, "%22>", Variabel, "</a>")) %>%
# engelmann
#mutate(Variabel = paste0("<a href=", SERVER_local, "?_inputs_&sidebarid=%22kaartekomplexer%22&variable=%22", variable, "%22>", Variabel, "</a>")) %>%
dplyr::select(-variable),
escape = FALSE,
#height = 600,
extensions = 'Scroller',
filter = 'top', options = list(
deferRender = TRUE,
scrollY = 900,
scroller = TRUE,
autoWidth = TRUE)
)
})
# stop App ----------------------------------------
# session$onSessionEnded(function() {
# stopApp()
# })
# shiny.route ----------------------------------------
router_server()
}