-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
91 lines (70 loc) · 2.52 KB
/
app.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
#Shiny ICCS databases
library(shiny)
library(ggplot2)
library(dplyr)
dir <- "C:/Users/pamel/OneDrive - KU Leuven/Master in Statistics/Master Thesis/DataAnalysis/"
load(file = paste0(dir,"Codebook.RData"))
Countries <- read_xlsx(paste0(dir,"Metadata.xlsx"), sheet = "CNT")
Files <- read_xlsx(paste0(dir,"Metadata.xlsx"), sheet = "Files")
Countries$year4 <- ifelse(Countries$year == "99", paste0("19",Countries$year), paste0("20",Countries$year))
#ui.R
ui <- fluidPage(
titlePanel("Shiny summary ICCS questionnaires"),
sidebarLayout(
sidebarPanel(
selectInput(inputId = "year",
label = "Choose a cycle:",
choices = c(sort(unique(Countries$year4))),
selected = "2016"),
uiOutput("datasetSelection"),
uiOutput("countrySelection")),
mainPanel(
verbatimTextOutput("summary"),
plotOutput("func"),
tableOutput("view")
)
)
)
#server.R
server <- function(input, output){
p1 <- reactive({
if (input$year == "2016") {
p1 <- VarsToUse %>%
filter(!is.na(VariableC3))
} else if (input$year == "2009") {
p1 <- VarsToUse %>%
filter(!is.na(VariableC2))
} else if (input$year == "1999") {
p1 <- VarsToUse %>%
filter(!is.na(VariableC1))
} else {
p1 <- VarsToUse %>%
filter(!is.na(VariableC3))
}
})
output$datasetSelection <- renderUI({
selectInput(inputId = "dataset",
label = "Choose a questionnaire:",
choices = c(sort(unique(p1()$Dataset))),
selected = c(sort(unique(p1()$Dataset))))
})
output$countrySelection <- renderUI({
checkboxGroupInput(inputId = "cnt",
label = "Country",
choices = eval(parse(text = as.character(Countries[Countries$year4 == input$year,"Country"]))),
selected = eval(parse(text = as.character(Countries[Countries$year4 == input$year,"Country"]))))
})
output$func <- renderPlot({
p <- ggplot(p1(), aes(x = Domain, color = Dataset, fill = Dataset)) +
geom_bar() +
facet_grid(. ~ Dataset) +
labs(title = "Description of questionnaire composition", x = "Domain", y = "Number of columns") +
theme(axis.text.x = element_text(angle = 90), legend.position = "none")
p
})
output$view <- renderTable({
mu <- p1() %>% filter(Dataset == input$dataset) %>% group_by(Dataset, Domain) %>% summarise(Nvar = n())
mu
})
}
shinyApp(ui = ui, server = server)