-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
137 lines (117 loc) · 4.31 KB
/
server.R
File metadata and controls
137 lines (117 loc) · 4.31 KB
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
library(dplyr)
library(GrowthSDS)
library(lubridate)
shinyServer(function(input, output, session) {
age <- reactive({
req(input$birthDate, input$observationDate)
time_length(interval(input$birthDate, input$observationDate), 'years')
})
heightCentile <- reactive({
req(input$sex, age(), input$height, input$reference)
sds(x = age(), y = input$height, sex = input$sex, measurement = 'height', refName = input$reference)
})
targetHeights <- reactive({
req(input$sex, input$motherHeight, input$fatherHeight, input$reference)
do.call(
rbind,
list(
data.frame(targetHeight(input$sex, input$motherHeight, input$fatherHeight, refName = input$reference)),
data.frame(targetHeight(input$sex, input$motherHeight, input$fatherHeight, method = 'Molinari', refName = input$reference)),
data.frame(targetHeight(input$sex, input$motherHeight, input$fatherHeight, method = 'Hermanussen', refName = input$reference))
)
)
})
targetHeightDifference <- reactive({
req(heightCentile(), targetHeights())
heightCentile() - filter(targetHeights(), method == 'Hermanussen')$sds[1]
})
output$heightCentile <- renderUI({
req(heightCentile())
age <- nearestX(x = age(), sex = input$sex, measurement = 'height', refName = input$reference)
tagList(
tags$b(paste0(round(heightCentile(), 2), ' SDS (p', round(pnorm(heightCentile()) * 100, 1), ')')),
tags$small(paste('Alter', round(age, 1), 'Jahre'))
)
})
output$targetHeightTable <- renderTable(targetHeights())
output$targetHeightDifference <- renderText({
req(targetHeightDifference())
paste('Differenz zu Zielgrößen-SDS (Hermanussen et al.):', round(targetHeightDifference(), 2))
})
output$targetHeightDifferenceResult <- renderText({
req(targetHeightDifference())
if (targetHeightDifference() <= -1) {
'Aktuelle Größe ist 1 SDS oder mehr unter der Zielgröße! Bitte auf SGA prüfen.'
} else {
''
}
})
# SGA
gestationalAge <- reactive({
req(input$gestationalAge)
floor(input$gestationalAge) + (input$gestationalAge %% 1 * 10) / 7
})
birthLengthCentile <- reactive({
req(input$birthSex, gestationalAge(), input$birthLength)
GrowthSDS:::evaluateCentiles(x = gestationalAge(), y = input$birthLength, ref = GrowthSDS::voigt@values$height[[input$birthSex]],
centiles = c(.03, .1, .5, .9, .97), zscores = c(-2, 2))
})
birthWeightCentile <- reactive({
req(input$birthSex, gestationalAge(), input$birthWeight)
GrowthSDS:::evaluateCentiles(x = gestationalAge(), y = input$birthWeight, ref = GrowthSDS::voigt@values$weight[[input$birthSex]],
centiles = c(.03, .1, .5, .9, .97), zscores = c(-2, 2))
})
output$birthLengthPlot <- renderPlot({
result <- birthLengthCentile()
req(result)
print(plotCentile(result, input$birthLength, 'Geburtslänge [cm]'))
})
output$birthWeightPlot <- renderPlot({
result <- birthWeightCentile()
req(result)
print(plotCentile(result, input$birthWeight, 'Geburtsgewicht [kg]'))
})
output$birthLengthEvaluation <- renderUI({
req(birthLengthCentile())
wellPanel(
tags$h4('Geburtslänge:', tags$b(paste0(
input$birthLength, ' cm (',
round(birthLengthCentile()$zscore, 2), ' SDS, p',
round(pnorm(birthLengthCentile()$zscore) * 100, 1), ')'
))),
uiOutput('birthLengthCentile'),
plotOutput('birthLengthPlot', height = 70)
)
})
output$birthWeightEvaluation <- renderUI({
req(birthWeightCentile())
wellPanel(
tags$h4('Geburtsgewicht:', tags$b(paste0(
input$birthWeight, ' kg (',
round(birthWeightCentile()$zscore, 2), ' SDS, p',
round(pnorm(birthWeightCentile()$zscore) * 100, 1), ')'
))),
uiOutput('birthWeightCentile'),
plotOutput('birthWeightPlot', height = 70)
)
})
# observers
observeEvent(input$sex, {
if (input$sex != input$birthSex) {
updateSelectInput(
session = session,
inputId = 'birthSex',
selected = input$sex
)
}
})
observeEvent(input$birthSex, {
if (input$birthSex != input$sex) {
updateSelectInput(
session = session,
inputId = 'sex',
selected = input$birthSex
)
}
})
})