library(shiny) library(ggplot2) library(dplyr) library(factoextra)

Charger les données

pauvrete <- read.csv(“./data/pauvrete.csv”) diplomes <- read.csv(“./data/diplomes.csv”) logements <- read.csv(“./data/logements.csv”) population <- read.csv(“./data/population.csv”)

ui <- fluidPage( navbarPage(“Analyse de la pauvreté en France”, tabPanel(“Comparaison des départements”, sidebarLayout( sidebarPanel( selectInput(“var”, “Choisir une variable:”, choices = names(pauvrete)) ), mainPanel( plotOutput(“top5_plot”), plotOutput(“caracterisation_plot”) ) ) ), tabPanel(“Facteurs socio-économiques”, sidebarLayout( sidebarPanel( selectInput(“facteur”, “Choisir un facteur:”, choices = names(diplomes)) ), mainPanel( plotOutput(“facteurs_plot”) ) ) ), tabPanel(“Analyse multivariée”, sidebarLayout( sidebarPanel( actionButton(“acp”, “Effectuer une ACP”) ), mainPanel( plotOutput(“acp_plot”) ) ) ) ) )

server <- function(input, output) {

output$top5_plot <- renderPlot({ top5 <- pauvrete %>% arrange(desc(Taux_pauvrete)) %>% head(5) ggplot(top5, aes(x = reorder(Departement, Taux_pauvrete), y = Taux_pauvrete)) + geom_bar(stat = “identity”, fill = “red”) + coord_flip() + labs(title = “Top 5 départements les plus pauvres”) })

output\(facteurs_plot <- renderPlot({ ggplot(diplomes, aes_string(x = "Departement", y = input\)facteur)) + geom_bar(stat = “identity”, fill = “blue”) + coord_flip() })

observeEvent(input\(acp, { acp_data <- pauvrete %>% select_if(is.numeric) res.pca <- prcomp(acp_data, scale = TRUE) output\)acp_plot <- renderPlot({ fviz_pca_var(res.pca) }) })

}

shinyApp(ui, server)