---
title: "ERFI premiers traitements - Quarto Dashboard"
echo: false
eval: false
format:
# dashboard: default
html:
code-tools:
source: true
toggle: false
caption: none
#server: shiny
---
Le tableau de bord créé avec Quarto dashboard est accessible [ici](https://solenne-roux.shinyapps.io/exemple_quarto_dashboard/).
Vous retrouverez le code qui a permis sa réalisation en cliquant sur le bouton *</>*... et en effaçant ces quelques lignes ;-)
Il faudra également dé-commenter la partie laissée en commentaire dans le YAML (en-tête du document) ; ainsi que supprimer l'instruction {.hidden} permettant de cacher les parties concernées.
A vous de jouer !!
# Indicateurs sociodémographiques {.hidden}
## Row
```{r}
#| title: "Sexe"
if (!require("pacman")) install.packages("pacman")
pacman::p_load(bslib, dplyr, ggplot2, here, readxl, shiny, shinylive, shinythemes, shinydashboard)
DF_path <- here("data", "DF_ERFI_anonym.xlsx")
DF <- read_excel(DF_path)
DF$MA_SEXE <- as.factor(DF$MA_SEXE)
DF2 <- subset(DF, select = MA_SEXE)
DF2<-na.omit(DF2)
tabsex<-table(DF2$MA_SEXE)
pie(tabsex, main = "Répartition selon le sexe", col = c("aquamarine", "darkgreen"), labels = c("Hommes", "Femmes"))
```
```{r}
#| title: "Age"
if (!require("pacman")) install.packages("pacman")
pacman::p_load(bslib, dplyr, ggplot2, here, readxl, shiny, shinylive, shinythemes, shinydashboard)
DF_path <- here("data", "DF_ERFI_anonym.xlsx")
DF <- read_excel(DF_path)
DF3 <- subset(DF, select = MA_AGEM_rec)
DF3 <- na.omit(DF3)
ggplot(DF3, aes(x=MA_AGEM_rec)) +
geom_density(fill="aquamarine", color="#e9ecef", alpha=0.8) +
ggtitle("Répartition par âge") +
theme_minimal()
```
## Row {.tabset}
```{r}
#| title: "Niveau de diplôme"
if (!require("pacman")) install.packages("pacman")
pacman::p_load(bslib, dplyr, ggplot2, here, readxl, shiny, shinylive, shinythemes, shinydashboard)
DF_path <- here("data", "DF_ERFI_anonym.xlsx")
DF <- read_excel(DF_path)
DF4 <- subset(DF, select = MC_DIPLOME)
DF4 <- na.omit(DF4)
DF4 <- DF4 |>
mutate(
MC_DIPLOME = factor(MC_DIPLOME, labels = c("Aucun diplôme", "CEP", "Brevet", "CAP/BEP",
"BAC tech ou pro", "BAC Général", "BAC +2", ">BAC+2"))
)
tabdipl<-table(DF4$MC_DIPLOME)
percdipl<-prop.table(tabdipl)
data<-data.frame(tabdipl, percdipl)
data$ymax <- cumsum(data$Freq.1)
data$ymin <- c(0, head(data$ymax, n=-1))
data$labelPosition <- (data$ymax + data$ymin) / 2
# Compute a good label
data$label <- paste0(data$Var1, "\n value: ", data$Freq)
# Make the plot
ggplot(data, aes(ymax=ymax, ymin=ymin, xmax=4, xmin=2, fill=Var1)) +
geom_rect() +
geom_label( x=3, aes(y=labelPosition, label=label), size=3) +
scale_fill_brewer(palette=4) +
coord_polar(theta="y") +
xlim(c(2, 4)) +
theme_void() +
theme(legend.position = "none")
```
```{r}
#| title: "Type de ménage"
if (!require("pacman")) install.packages("pacman")
pacman::p_load(bslib, dplyr, ggplot2, here, readxl, shiny, shinylive, shinythemes, shinydashboard)
DF_path <- here("data", "DF_ERFI_anonym.xlsx")
DF <- read_excel(DF_path)
DF5 <- subset(DF, select = TYPFAM3_rec)
DF5 <- na.omit(DF5)
DF5 <- DF5 |>
mutate(
TYPFAM3_rec = factor(TYPFAM3_rec, labels = c("Seul sans enfant ", "Seul avec enfant(s) ", "En couple sans enfant ", "En couple avec enfant(s) ","Ménage de plusieurs personnes"))
)
tabmen<-table(DF5$TYPFAM3_rec)
percmen<-prop.table(tabmen)
data2<-data.frame(tabmen, percmen)
data2$ymax <- cumsum(data2$Freq.1)
data2$ymin <- c(0, head(data2$ymax, n=-1))
data2$labelPosition <- (data2$ymax + data2$ymin) / 2
# Compute a good label
data2$label <- paste0(data2$Var1, "\n value: ", data2$Freq)
# Make the plot
ggplot(data2, aes(ymax=ymax, ymin=ymin, xmax=4, xmin=2, fill=Var1)) +
geom_rect() +
geom_label( x=3, aes(y=labelPosition, label=label), size=2.5) +
scale_fill_brewer(palette=3) +
coord_polar(theta="y") +
xlim(c(-2, 4)) +
theme_void() +
theme(legend.position = "none")
```
# Satisfaction de la répartition des tâches ménagères selon le sexe {.hidden}
## {.sidebar}
```{r}
#| context: setup
if (!require("pacman")) install.packages("pacman")
pacman::p_load(bslib, dplyr, ggplot2, here, readxl, shiny, shinythemes)
DF_path <- here("data", "DF_ERFI_anonym.xlsx")
DF <- read_excel(DF_path)
DF$OA_SATREP <- as.numeric(DF$OA_SATREP)
DF$MA_SEXE <- as.factor(DF$MA_SEXE)
DF2 <- subset(DF, select = c(OA_SATREP, MA_SEXE))
DF2 <- na.omit(DF2)
levels(DF2$MA_SEXE) <- c("Hommes", "Femmes")
```
```{r}
selectInput(
inputId = "gender",
label = "Sélectionner le genre :",
choices = c("Tous" = "Tous", "Hommes" = "Hommes", "Femmes" = "Femmes"),
selected = "Tous"
)
```
## Column {width=70%}
### Row {width=30%}
```{r}
#| content: valuebox
#| title: Hommes
list(
icon = "gender-male",
color = "aquamarine",
value = 2823
)
```
```{r}
#| content: valuebox
#| title: Femmes
list(
icon = "gender-female",
color = "steelblue",
value = 3265
)
```
### Row {width=70%}
```{r}
plotOutput("histPlot", height = "500px")
```
```{r}
#| context: server
dataset <- reactive({
DF2[sample(nrow(DF2), input$gender),]
})
output$histPlot <- renderPlot({
filtered_data <- DF2
if (input$gender != "Tous") {
filtered_data <- DF2 %>% filter(MA_SEXE == input$gender)
}
if (input$gender == "Tous") {
p <- ggplot(filtered_data, aes(x = OA_SATREP, fill = MA_SEXE)) +
geom_histogram(bins = 30, position = "dodge") +
facet_wrap(~ MA_SEXE, ncol = 2) +
labs(
title = "Histogramme de la satisfaction (Tous)",
x = "Satisfaction de la répartition des tâches ménagères",
y = "Fréquence"
) +
theme_minimal() +
scale_fill_manual(values = c("Hommes" = "aquamarine", "Femmes" = "steelblue"))
} else {
gender_color <- if (input$gender == "Hommes") "aquamarine" else "steelblue"
p <- ggplot(filtered_data, aes(x = OA_SATREP)) +
geom_histogram(bins = 30, fill = gender_color, color = "black") +
labs(
title = paste("Histogramme de la satisfaction (", input$gender, ")", sep = ""),
x = "Satisfaction de la répartition des tâches ménagères",
y = "Fréquence"
) +
theme_minimal() +
theme(legend.position = "none")
}
print(p)
})
```